I have an array with nested objects, such as this one:
[
{"name": "1", "children": [{"name": "1.1", "children":"1.2"}]},
{"id": "2", "thing": [{"name": "2.1", "children":"2.2"}]},
{"name": "3", "stuff": [{"name": "3.1", "children":"3.2"}]},
]
The objects can contain values of different types, including other, nested objects.
I want to convert this array to CSV format.
I've tried to iterate with for .. in
loops, regular nested for
loops, .map()
and recursion. I think recursion might be the only way to solve this particular problem, though. For the CSV field names I want to use the sequence of keys that lead to the value.
For the given example, the CSV result I'm looking for is:
name, children.name, children.children,id, thing.name, thing.children, stuff.name, stuff.children
1, 1.1, 1.2,
,,,2,2.1,2.2
3,,,,3,3.1,3.2