title: Encoding nested JSON in Go
body: <p>I've had a lot of trouble finding an example of this. Most of the information on the internet is about decoding JSON.</p>
  
  <p>I'd like to serialize some data into nested JSON, like for example:</p>
  
  <pre><code>{
    "item": {
        "title": "Items",
      "properties": [
        {
          "num": 1,
          "name": "Item 1"
        },
        {
          "num": 2,
          "name": "Item 2"
        }
      ]
    }
  }
  </code></pre>
  
  <p>I know how to marshal data with a flat struct, but how do I put data into a struct that can be serialized with nesting?</p>
  
  <p><a href="http://play.golang.org/p/nDKmv1myTD" rel="nofollow">http://play.golang.org/p/nDKmv1myTD</a></p>
  
  <p>I found this tool that generates a struct from a JSON schema, but I don't understand how to get data into the sub structs.</p>
  
  <p><a href="http://mholt.github.io/json-to-go/" rel="nofollow">http://mholt.github.io/json-to-go/</a></p>
  
  <pre><code>type Example struct {
      Item struct {
          Title string `json:"title"`
          Properties []struct {
              Num int `json:"num"`
              Name string `json:"name"`
          } `json:"properties"`
      } `json:"item"`
  }
  </code></pre>