I'm pretty new to golang and struggling a bit with converting flat database results into a nested JSON object.
As an example... I have type item struct { raceID string racename string name string votes int32 } type race struct { raceID string racename string racers } type racers []racer type racer struct { name string votes int32 } []item is what I get back from my db query and I want to convert it into a json object that matches the race struct. basically I want to convert items := []item{ item{"1", "racename1", "scooby", 1000}, item{"1", "racename1", "scrappy", 9000}, item{"1", "racename1", "shaggy", 1000}, item{"2", "racename2", "shaggy", 450}, item{"2", "racename2", "fred", 550}, } into something like [{ "raceID": "1", "racename": "racename1", "racers": [{ "name": "scooby", "votes": 1000 }, { "name": "scrappy", "votes": 9000 }, { "name": "shaggy", "votes": 1000 }] }, { "raceID": "2", "racename": "racename2", "racers": [{ "name": "shaggy", "votes": 450 }, { "name": "fred", "votes": 550 }] }] I'm pretty sure I need to use maps and append some slices... but any pointing in the right direction would surely be appreciated. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.