My goal is to iterate through a Json object structured like this
[
{
"yang_type": "container",
"name": "c1",
"value": "",
"children": [
{
"yang_type": "",
"name": "type",
"value": "Uint32",
"children": []
},
{
"yang_type": "list",
"name": "DNS",
"value": "",
"children": [
{
"name": "type",
"value": "String",
"children": [],
"yang_type": ""
},
{
"yang_type": "leaf",
"name": "ip-address",
"value": "",
"children": [
{
"name": "type",
"value": "string",
"children": [],
"yang_type": ""
}
]
},
{
"yang_type": "leaf",
"name": "Domain",
"value": "",
"children": [
{
"name": "type",
"value": "string",
"children": [],
"yang_type": ""
}
]
}
]
}
]
}
]
I've implemented the following logic, but it fails to iterate through all the children elements.
while(m.children.length >= 1) {
if(m.yang_type!='' && m.name!=''){
{$log.error("parent:",m.yang_type,m.name);}
}
if(m.name!='' && m.value!=''){
{$log.error("child:",m.name,m.value);}
}
m = m.children[m.children.length - 1];
}
The existing code seems to be missing the iteration over certain child nodes. What am I doing incorrectly?