I'm trying to build a dynamic tree structure in html. I'm getting result from database in nested json format.
I'm not able to read the json data properly. It is in the format
[ { keys_1 : { keys_2 : [ array ] } } ]
In the tree structre, key_1 are the parents, key_2 are childern, array items are grand-childern.
How to access this json data so that i can read the parent keys, associated children and then grand children.
I tried this way but couldn't do that:
for (var i = 0; i < response.length; i++) {
var level_1 = (JSON.stringify((Object.keys(response[i]))[0])).replace(/"/g, "");
for (var j = 0; j < response[i].length; j++) {
console.log("yes");
}
}
Even, i'm not able to figure out how to enter the nested json with different key values. - All keys are different. - Keys may/may not have children, same with the children also.
How to read the json data in that way so that first it should read one parent children then grandchildren?