title: How to unmarshall an array of different types correctly?
body: <p>As long as I have key-value pairs unmarshalling is pretty straight forward but how would I unmarshall an array of different types in different order? The single elements are well defined and known but the order is not.</p>
  
  <p>I can not come up with a beautiful solution.</p>
  
  <p>Would I try and error over all elements?
  Is there some kind of union type that could do that for me?</p>
  
  <p><a href="http://play.golang.org/p/ZVPW7eYJh2" rel="noreferrer">playground version</a></p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
  )
  
  var my_json string = `{
      "an_array":[
          "with_a string",
          {
              "and":"some_more",
              "different":["nested", "types"]
          }
      ]
  }`
  
  type MyInner struct {
      And     string
      Different   []string
  }
  
  type MyJSON struct {
      An_array []json.RawMessage
  }
  
  func main() {
      var my_json_test MyJSON
  
      e := json.Unmarshal([]byte(my_json), &amp;my_json_test)
      if e != nil {
          fmt.Println(e)
      } else {
          for index, value := range my_json_test.An_array {
              fmt.Println("index: ", index)
              fmt.Println("value: ", string(value))
          }
          var my_inner MyInner
          err := json.Unmarshal(my_json_test.An_array[1], &amp;my_inner)
          if err != nil {
              fmt.Println(err)
          } else {
              fmt.Println("inner structure: ", my_inner)
          }
      }
  }
  </code></pre>