I have a JSON file that comes in a particular structure (see Tree), but I need it too be structured like expected output.
Is it possible to reorganise the data in JS? If so, how do you go about this? I need help in restructuring or mapping the tree to the expected output. I hope you guys can help me with this restructuring problem.
const tree = [
{
"type": "object",
"name": "pets",
"child":
[
{
type: "array",
name: "properties",
"child":
[
{
type: "object",
name: "PK",
},
{
type: "object",
name: "PO",
},
{
type: "object",
name: "PS",
},
{
type: "object",
name: "PA",
child: [{type: "array", name: "list"}, ]
},
]
},
{
type: "object",
name: "get",
}
]
},
]
const expectedResult = [
{
pets:
{
properties:
[
{
name: "PK"
},
{
name: "PO"
},
{
name: "PS"
},
{
"PA" :
{
list: []
}
}
],
get: {}
}
},
]
treealways an array? Or always an array with single object in it?