Unmarshal into struct where root struct field is a dynamic field

56 views
Skip to first unread message

vanmuld...@gmail.com

unread,
Dec 6, 2016, 5:02:57 PM12/6/16
to golang-nuts
An example JSON response :

Query : /id/123456

Response : 


  {"123456":{"id":123456,"name":"qsdsdqsdqsd","profileIconId":23}}

The root struct field is a dynamic field based of the parameter I queried?
Is is possible to unmarshal to a struct or should I use map[string] approach and dig a level deeper myself and then unmarshal that into a struct?


Viktor Kojouharov

unread,
Dec 7, 2016, 3:56:19 AM12/7/16
to golang-nuts, vanmuld...@gmail.com

It seems to me that the response is always a map[string]SomeStruct{}. Nothing wrong with that.
Reply all
Reply to author
Forward
0 new messages