Re: Flatten nested dictionaries

506 views
Skip to first unread message

Carl Johnson

unread,
Apr 18, 2013, 1:08:18 AM4/18/13
to golan...@googlegroups.com
Go back to the very beginning. Your Dict type is a map[string] string. map[string] string can't hold a key-value pair that's string-Dict. It can only hold string-string pairs. So, from the start, you're not going to have any kind of nested dictionary at all until you fix that. There are a couple of ways. You could do type Dict map[string] Dict. But then you only have nested dictionaries and no unnested ones. Or you could do map[string] interface{}, which is closer to what you have in Python or Ruby.

Kelley Robinson

unread,
Apr 21, 2013, 7:29:02 PM4/21/13
to golan...@googlegroups.com
Awesome, I ended up with the following. Still testing for edge cases but it's functional for flattening most JSON.

Reply all
Reply to author
Forward
0 new messages