I have a JSON that looks like this:
[
{
"type":"car",
"types":[
{
"type":"ferrari",
"types":[
{
"type":"big",
"count":5
},
{
"type":"small",
"count":1
}
]
},
{
"type":"volvo",
"types":[
{
"type":"big",
"count":2
}
]
}
]
},
{
"type":"bike",
"types":[
{
"type":"Ducati",
"types":[
{
"type":"small",
"count":1
}
]
}
]
}
]
It's like a "group by" but nested. I want to convert it so that it is not nested. Something like this:
[
{
"types":[ "car", "ferrari", "big" ],
"count":5
},
{
"types":[ "car", "ferrari", "small" ],
"count":1
},
{
"types":[ "car", "volvo", "big" ],
"count":2
},
{
"types":[ "bike", "ducati", "small" ],
"count":1
}
]
I got stuck because it's a recursive function, but complicated because I need to create a JObject for each combination. Actually more complicated because I don't know how nested the answer is. I know to stop when there is no types property.
I'm trying to do this with JObjects.