In my current project I need to display a JSON file in a tree (angular2-tree-component). For the tree to recognize the JSON objects, each object needs an ID. I want to add the ID with Depth first search.
But currently I have no idea how to implement this.
My JSON structure:
var test = [{
object:
[{
name2: "name2",
name3: "name3",
object: [{
name4: "name4",
name5: "name5",
object: [{
name6: "name6",
}]
}]
}]
}]
Accepted output:
nodes = [
{
id: 1,
name: 'root1',
children: [
{ id: 2, name: 'child1' }
]
},
{
id: 4,
name: 'root2',
children: [
{ id: 5, name: 'child2.1' }
]
}
];