I have the following data structure
[
{
"id": 3,
"name" "Important Topic 3",
"questions": [array of questions],
"topics: [array of topics],
"parentTopic": {
"id": 2,
"name": "Parent Topic 1",
"parentTopic": {
"id": 1,
"name": "Parent Topic 2",
"parentTopic: null
}
}
},
{
"id": 4,
"name" "Important Topic 4",
"questions": [array of questions],
"topics: [array of topics],
"parentTopic": {
"id": 2,
"name": "Parent Topic 1",
"parentTopic": {
"id": 1,
"name": "Parent Topic 2",
"parentTopic: null
}
}
}
]
I want to end up with the following
[
{
"id": 1,
"name": "Parent Topic 2",
"topics": [
{
"id": 2,
"name": "Parent Topic 1"
"topics": [
{
"id": 3,
"name: "Important Topic 3",
"questions": [array of questions],
"topics: [array of topics]
},
{
"id": 4,
"name: "Important Topic 4",
"questions": [array of questions],
"topics: [array of topics]
}
]
}
]
}
]
I have some code which I got also as help from the awesome stackoverflow community, but it only works if I have nested dictionary objects, not lists of dictionaries in an array. Here is the stackoverflow reference - Reverse Nested Tree in Javascript
I would really appreciate if you could help solve this puzzle :)
topicsshould be, the question is then what happens to -- and what is the relevance of -- the originaltopicsproperties?