Looking to transform an existing JSON object into a new object structure.
Here is the current JSON object:
{
"name": "Parent",
"children": [
{
"name": "Child1",
"children": [
{
"name": "GrandChid1",
"children": []
},
{
"name": "GrandChild2",
"children": []
},
{
"name": "GrandChild3",
"children": [
{
"name": "GrandGrandChild1",
"children": [
{
"name": "GrandGrandGrandChild1",
"children": []
},
{
"name": "GrandGrandGrandChild2",
"children": []
}
]
}
]
}
]
}
]
}
The desired new object structure:
{
"Parent": [
{
"Child1": [
{
"GrandChid1": ''
},
{
"GrandChild2": ''
},
{
"GrandChild3": [
{
"GrandGrandChild1": [
{
"GrandGrandGrandChild1": ''
},
{
"GrandGrandGrandChild2": ''
}
]
}
]
}
]
}
]
}
In case there are no children, the object value becomes a string (key-value pair). A recursive solution is sought for this task, any assistance is appreciated.