here is a json object i want to loop through:
{
node: 'tree',
text: 'Main Node',
childs:[
{
node: 'tree',
text: 'First Child',
childs:[{
node: 'tree',
text: 'first child child'
}....]
},{
node: 'tree',
text: '2nd Child',
childs:[{
node: 'tree',
text: '2nd child child'
}...]
}...]
}
here is the first type of json. but the problem is that json is dynamic and the child element vary depend upon different conditions. so i want to loop through the json and add leaf: true to the end of the last nested element. here is what is want:
{
node: 'tree',
text: 'Main Node',
childs:[
{
node: 'tree',
text: 'First Child',
childs:[{
node: 'tree',
text: 'first child child',
leaf: true // i want to add this node to every last one
}]
},{
node: 'tree',
text: '2nd Child',
childs:[{
node: 'tree',
text: '2nd child child',
leaf: true
}]
}]
}