title: How do I json unmarshal slice inside a slice
body: <p>I am trying to unmarshal some pretty ugly json but can't figure out how. I have:</p>
  
  <pre><code>package main
  
  import "fmt"
  import "encoding/json"
  
  type PublicKey struct {
      ID     int    `json:"id"`
      Key    string `json:"key"`
      MyData []struct {
          ID    string `json:"id"`
          Value int    `json:"value"`
      }
  }
  
  func main() {
      b := `[
    {
      "id": 1,
      "key": "my_key"
    },
    [
      {
        "id": "some_id",
        "value": 12
      },
      {
        "id": "anorther_id",
        "value": 13
      }
    ]
  ]`
  
      var pk []PublicKey
      err := json.Unmarshal([]byte(b), &amp;pk)
      if err != nil {
          fmt.Println(err)
      }
      fmt.Println(pk)
  
  }
  </code></pre>
  
  <p>For the result I am getting:</p>
  
  <pre><code>[{1 my_key []} {0  []}]
  </code></pre>
  
  <p>The second slice is empty when it shouldn't be. </p>
  
  <p><strong>EDIT</strong>:
  The error I get is:</p>
  
  <pre><code>json: cannot unmarshal array into Go struct field PublicKey.key of type main.PublicKey
  </code></pre>
  
  <p><a href="https://play.golang.org/p/cztXOchiiS5" rel="nofollow noreferrer">https://play.golang.org/p/cztXOchiiS5</a></p>