[
{
"level_key":"lvl1",
"level_value":"Code1",
"values":[
{
"name":"a",
"value":0
},
{
"name":"b",
"value":0
}
],
"children":[
{
"level_key":"lvl2",
"level_value":"Type1",
"values":[
{
"name":"a",
"value":0
},
{
"name":"b",
"value":0
}
],
"children":[
{
"level_key":"lvl3",
"level_value":"Desc1",
"values":[
{
"name":"a",
"value":0
},
{
"name":"b",
"value":0
}
],
"children":[
{
"level_key":"lvl4",
"level_value":"Check1",
"values":[
{
"name":"a",
"value":2
},
{
"name":"b",
"value":3
}
],
"children":[]
},
{
"level_key":"lvl4",
"level_value":"Check2",
"values":[
{
"name":"a",
"value":4
},
{
"name":"b",
"value":5
}
],
"children":[]
}
]
}
]
}
]
}
]
I've attempted to tackle the issue by repeatedly looping through different levels, but this approach is flawed due to the varying number of levels. Here is the initial input:
[ { "level_key":"lvl1", "level_value":"Code1", "values":[ { "name":"a", "value":0 }, { "name":"b", "value":0 } ], "children":[ { "level_key":"lvl2", "level_value":"Type1", "values":[ { "name":"a", "value":0 }, { "name":"b", "value":0 } ], "children":[ { "level_key":"lvl3", "level_value":"Desc1", "values":[ { "name":"a", "value":0 }, { "name":"b", "value":0 } ], "children":[ { "level_key":"lvl4", "level_value":"Check1", "values":[ { "name":"a", "value":2 }, { "name":"b", "value":3 } ], "children":[] }, { "level_key":"lvl4", "level_value":"Check2", "values":[ { "name":"a", "value":4 }, { "name":"b", "value":5 } ], "children":[] } ] } ] } ] } ] I have attempted a brute force method where I iterated through the maximum possible number of levels, which is not ideal as the number of levels can vary. The expected output should be:
[
{
"level_key":"lvl1",
"level_value":"Code1",
"values":[
{
"name":"a",
"value":6
},
{
"name":"b",
"value":8
}
],
"children":[
{
"level_key":"lvl2",
"level_value":"Type1",
"values":[
{
"name":"a",
"value":6
},
{
"name":"b",
"value":8
}
],
"children":[
{
"level_key":"lvl3",
"level_value":"Desc1",
"values":[
{
"name":"a",
"value":6
},
{
"name":"b",
"value":8
}
],
"children":[
{
"level_key":"lvl4",
"level_value":"Check1",
"values":[
{
"name":"a",
"value":2
},
{
"name":"b",
"value":3
}
],
"children":[]
},
{
"level_key":"lvl4",
"level_value":"Check2",
"values":[
{
"name":"a",
"value":4
},
{
"name":"b",
"value":5
}
],
"children":[]
}
]
}
]
}
]
}
]