Please I want to transform the JSON below into an array of objects. I'm pretty bad at recursion and i have struggled all day. Please help will be appreciated.
{
"org_name":"paradise island",
"daughters" : [
{
"org_name": "banana tree",
"daughters": [
{"org_name":"Yellow Banana"},
{"org_name":"Brown Banana"}
]
},
{
"org_name": "big banana tree",
"daughters": [
{"org_name":"green banana"},
{"org_name":"yellow banana"},
{
"org_name": "Black banana",
"daughters": [
{"org_name": "red spider"}
]
}
]
}
]
}
I want it to be transformed as below:
[
{id:1, name:'paradise island', parent: null},
{id:2, name:'Banana Tree', parent: 1},
{id:3, name:'yellow banana', parent: 2}
]
The order doesn't matter. What is important is correct id relationship as per parent to child. I intend to generate the id as UUIDs. But you can generate it anyhow you like.