mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.51k stars 475 forks source link

Named types fails on arrays of objects #50

Closed jcbwlkr closed 5 years ago

jcbwlkr commented 5 years ago

Hello! Thanks for this great tool. I tried out the new non-anonymous structs feature and noticed a bug so I thought to let you know.

When you have an object that has a field which is an array of objects the generator fails. For example, this input:

{
  "users": [
    {
      "name": "Gopher"
    }
  ]
}

When used with the classic behavior it works fine. When I uncheck the box so I get two separate types I instead get this

2:11: expected type, found 'STRING' `json:"users"`
mholt commented 5 years ago

Oops, it's possible that I broke this by adding a \n somewhere, recently.