Here is an example of a JSON array called items:
var items = [
{
Id: "c1",
config:{
url:"/c1",
content: "c1 content",
parentId: "p1",
parentUrl: "/p1",
parentContent: "p1 content",
}
},
{
Id: "c2",
config:{
url:"/c2",
content: "c2 content",
parentId: "p1",
parentUrl: "/p1",
parentContent: "p1 content",
}
},
{
Id: "c3",
config:{
url:"/c3",
content: "c3 content"
}
},
]
The desired output should look like this:
var items = [
{
Id: "p1",
config:{
url:"/p1",
content: "p1 content"
},children:[
{
Id: "c1",
config:{
url:"/c1",
content: "c1 content"
}
},{
Id: "c2",
config:{
url:"/c2",
content: "c2 content"
}
},
]
},
{
Id: "c3",
config:{
url:"/c3",
content: "c3 content"
}
},
]
If an object has parent properties, they should be nested under the parent's children property. If you need help converting this structure, feel free to ask for assistance. Thank you.