I have an array of objects like so:
{
"sCode": "1010",
"PCode": "1011",
"category": "Diagnostic",
"procedure": "Oral assessment for patients up to the age of 3 years inclusive. ",
"serviceClassification": "First Dental Visit/Orientation",
},
I'm trying to group by category
and create an array called children, then this array has another nested array of children grouped by serviceClassification
Desired Output
[
{
"id": "Diagnostic",
"text": "Diagnostic",
"children": [
{
"id": "FIRST DENTAL VISIT/ORIENTATION",
"text": "FIRST DENTAL VISIT/ORIENTATION",
"children": [
{
"id": 0,
"text": "01011 - Oral assessment for patients up to the age of 3 years inclusive."
}
]
}
I have been trying for couple of hours, here is a code sample of what I have tried: