title: What is the best way to work with nested JSON structures in Golang?
body: <p>Id like to work with JSON in Golang, in particular the elastic search JSON protocol.</p>
  
  <p>The JSON is deeply nested (this is a simple query):</p>
  
  <pre><code>{
      "query": {
          "filtered": {
              "query": {
                  "match_all": {}
              },
              "filter": {
                  "and": [
                      {
                          "range" : {
                              "b" : { 
                                  "from" : 4, 
                                  "to" : "8"
                              }
                          },
                      },
                      {
                          "term": {
                              "a": "john"
                          }
                      }
                  ]
              }
          }
      }
  }
  </code></pre>
  
  <p>This structure maps easily to a native data structure in Ruby.</p>
  
  <p>But with Golang, it seems you have to define the exact structure with structs (perhaps generate them programmatically from the JSON source).</p>
  
  <p>Even so, things like arrays of different "types" of objects in JS requires work arounds and custom code. For example the "and" key in the example JSON. (<a href="http://mattyjwilliams.blogspot.co.uk/2013/01/using-go-to-unmarshal-json-lists-with.html" rel="noreferrer">http://mattyjwilliams.blogspot.co.uk/2013/01/using-go-to-unmarshal-json-lists-with.html</a>).</p>
  
  <p>Is there a better way to work with JSON in Golang?</p>