I'm making a treemap in d3, which requires data as a series of nested objects, like so:
{
name: "flare",
children: [
{
name: "analytics",
children: [
{
name: "cluster",
children: [
{
name: "AgglomerativeCluster",
size: 3938
},
{
name: "CommunityStructure",
size: 3812
}
]
}
]
}
]
}
The natural way to gather this data behind the scenes is as a dictionary (in Python terminology), like so:
{
"flare": {
"analytics": {
"cluster": [
{
name: "AgglomerativeCluster",
size: 3938
},
//etc etc
What's the most natural way to get from the latter to the former without writing nested loops by hand?