I need help to come up with a solution to retrieve all possible paths to an array containing several JSON objects containing the two keys: name[String] and children [Array]. For any given JSON input, I need an array of strings with all routes in the JSON, returning only the name of each item. The input array object can contain any number of nested children.
For example:
Obj = [
{ name: ‘name1’ },
{ name: ‘name2’ },
{ name: ‘name3’, children:[
{ name: name3Child1 },
{ name: name3Child2 },
{ name: name3Child3, children:[{ name: 'name3Child3Child1' }] }
]
},
{ name: ‘name4’ },
]
With the above example, the output I'll need is:
result = [
'name1',
'name2',
'name3',
'name3.name3Child1',
'name3.name3Child2',
'name3.name3Child3.name3Child3Child1',
'name4',
]
If you can provide ES6+ examples, I'd really appreciate it. I've searched online but many examples relate to standard JSON objects, where as this is in a custom format.
Thanks