I have json data that looks like this:
{
"domain": {
"id": "40d74976-5db2-4a57-2a62-08d80969933d",
"name": "A",
"categories": {
"items": [
{
"id": "b17e674a-b64d-4224-bf93-016bc07b6349",
"name": "Category A",
"path": "A/Category A"
},
{
"id": "f6490fe4-98b0-4918-a419-0177000227c2",
"name": "Category AA",
"path": "A/Category A/Category AA"
},
{
"id": "092163a5-b96f-4453-8a22-0307c1f1abec",
"name": "Category B",
"path": "A/Category B"
},
{
"id": "78ac6a08-4dc4-4f60-b0fd-0411b9631c4a",
"name": "Category B-2",
"path": "A/Category B/Category B-2"
}
]
}
}
}
And i would like the result to be this:
{
"domain": {
"id" : "40d74976-5db2-4a57-2a62-08d80969933d",
"name": "A",
"categories": {
"items": [
{
"id": "b17e674a-b64d-4224-bf93-016bc07b6349",
"name": "Category A",
"path": "A/Category A"
"children": [
{
"id": "f6490fe4-98b0-4918-a419-0177000227c2",
"name": "Category AA",
"path": "A/Category A/Category AA"
}
]
},
{
"id": "092163a5-b96f-4453-8a22-0307c1f1abec",
"name": "Category B",
"path": "Domain A/Category B"
"children" :[
{
"id": "78ac6a08-4dc4-4f60-b0fd-0411b9631c4a",
"name": "Category B-2",
"path": "A/Category B/Category B-2"
}
]
}
]
}
}
}
I need to convert the json data in this way because i want to display this in the treeview format on my vue application but also retain the original id of each element since i want to implement the feature allow adding children to each specific element if the user needs to. To do that, it would need the original path of that element and the id of the element to which the child is being added