I'm working in Javascript.
I'm trying to convert an array of arrays into a nested JSON object.
Here is the array of arrays. Each array represents a branch of a tree.
LoL = [["parent", "child1", "grandchild1"],
["parent", "child1", "grandchild2"],
["parent","child2", "grandchild3"]]
I need to reformat this data into a nested JSON object, something like:
json = {
"name": "parent",
"children": [
{
"name": "child1",
"children": [
{
"name": "grandchild1"
},
{
"name": "grandchild2"
}
]
},
{
"name": "child2"
"children":[
{
"name":"grandchild3"
}
]
}
]};
(essentially trying to turn an array of arrays to match the flare.json found in this project: http://bl.ocks.org/emeeks/4733217)
What would be the best approach to reformat?
|, it is the same question. Here's a fiddle: jsfiddle.net/adigas/u16dnLro