Having some trouble converting a nested hierarchical tree from a JSON array. Looking to create a hierarchical tree structure from the provided JSON data.
Below is the data:
[{
"_id" : "59b65ee33af7a11a3e3486c2",
"C_TITLE" : "Sweet and Snacks",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets.jpg",
"C_STATUS" : "Active"
}
{
"_id" : "59b663d709da571dc3d79f49",
"C_TITLE" : "Groceries",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b663d709da571dc3d79f49_grocery.jpg",
"C_STATUS" : "Active"
},
{
"_id" : "59b6648209da571dc3d79f4a",
"C_TITLE" : "Dals & Pulses",
"C_PARENT" : "59b663d709da571dc3d79f49",
"C_ICON" : "",
"C_IMAGE" : "59b6648209da571dc3d79f4a_dals.jpg",
"C_STATUS" : "Active"
},
{
"_id" : "59b6657509da571dc3d79f4c",
"C_TITLE" : "Rice & Rice products",
"C_PARENT" : "59b663d709da571dc3d79f49",
"C_ICON" : "",
"C_IMAGE" : "59b6657509da571dc3d79f4c_rice.jpg",
"C_STATUS" : "Active"
}]
Looking for an output structure like this:
[
{
" _id" : "59b65ee33af7a11a3e3486c2",
"C_TITLE" : "Sweet and Snacks",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets.jpg",
"C_STATUS" : "Active",
children:[]
}
]
Matching the data based on the C_PARENT and _id fields.