I have a REST API from which i am fetching the json data and storing them in array. The API looks like below:
[
{
"id": "100",
"name": "Person1",
"number": "+91-8980439023"
},
{
"id": "102",
"name": "Person2",
"number": "+91-5980339023"
},
{
"id": "105",
"name": "Person3",
"number": "+91-8980439023"
},
{
"id": "101",
"name": "Person4",
"number": "+91-8980439023",
"parent": "105"
},
{
"id": "110",
"name": "Person5",
"number": "+91-8980439023"
},
{
"id": "115",
"name": "Person6",
"number": "+91-9834295899",
"parent": "100"
}
]
Some of the data have "parent" field.The value in the "parent" field is the "id" of the other data. Now i want to store these data which have reference in the "parent" field of other data in a separate array. For example: The data with id=101 has "parent" key with value 105 which in turn is the id of the 3rd data.So the data with id=105 should be stored in separate array.
How can i do in a simple and scalable way?