title: golang querying database using Gorm and returning json in http response
body: <p>I'm new to Go and am using Gorm to query my postgres database but am having trouble returning my data in a dictionary format, where the pokemon's type serves as a key to an array of all the pokemon of that type</p>
  
  <blockquote>
    <p>json: cannot unmarshal object into Go value of type []models.Pokemon</p>
  </blockquote>
  
  <p>here's my code:</p>
  
  <pre><code>type Pokemon struct {
      Name   string   `db:"name"`
      Type   string   `db:"type"`
  }
  
  pokemonTypes := [6]string{
      "fire",
      "electric",
      "water",
      "grass",
  }
  
  var retData struct {
     Poke []Pokemon
  }
  
  m := make(map[string][]Pokemon)
  
  for _, t := range pokemonTypes {
      pokemon := DB.Where(&amp;Pokemon{Type: t}).Find(&amp;retData.Poke)
      p, _ := json.Marshal(pokemon)
      err = json.Unmarshal(p, &amp;retData.Poke)  // getting error here
      if err != nil {
          fmt.Println(err)
      }
      m[category] = retData.Poke
  }
  
  data, _ := json.Marshal(m) 
  w.Write(data)  // http repsonse
  </code></pre>
  
  <p>I have this in my database</p>
  
  <pre><code>name       | type
  ----------------------
  pikachu    | electric
  charmander | fire
  blaziken   | fire
  venusaur   | grass
  treeko     | grass
  squirtle   | water
  </code></pre>
  
  <p>I want to return data in this json format  </p>
  
  <pre><code>{
    “electric”: [
      {"name": "pikachu", "type": "electric"},
    ],
    "fire": [
      {"name": "charmander", "type": "fire"},
      {"name": "blaziken", "type": "fire"}
    ],
    "grass": [
      {"name": "venusaur", "type": "grass"},
      {"name": "treeko", "type": "grass"},
    ],
    "water": [
      {"name": "squirtle", "type": "water"},
    ]
  }
  </code></pre>