I have an object, I need to parse and put in another object from format 1 to format 2.
Format 1:
let mydata=[{
"_children": {
"5": {
"_children": {
"7": {
"_children": {},
"id": "7",
"name": "subject11",
"parentID": 5
},
"10": {
"_children": {},
"id": "10",
"name": "subject12",
"parentID": 5
}
},
"id": "5",
"name": "subject1",
"parentID": null
},
"6": {
"_children": {
"8": {
"_children": {},
"id": "8",
"name": "subject21",
"parentID": 6
},
"9": {
"_children": {},
"id": "9",
"name": "subject22",
"parentID": 6
}
},
"id": "6",
"name": "subject2",
"parentID": null
}
}
}]
Format 2:
let endresult=[
{"id":7, "name":"subject11", "parent":"subject1"},
{"id":10, "name":"subject12", "parent":"subject1"}
{"id":8, "name":"subject21", "parent":"subject2"},
{"id":9, "name":"subject22", "parent":"subject2"},
]
Do you have any idea?
2
Answers
tldr:
You could get the entries and a flat array as result.