What im trying to do is create a function that convert this array
{
"data": {
"churnStructured": [
{
"id_region": "4",
"iso": "be",
"mcc": "206",
"country": "Belgium",
"carriers": [
{
"carrier": "Triton PCS",
"id_carrier": 68,
"brands": []
},
{
"carrier": "Beeline",
"id_carrier": 80,
"brands": []
}
]
},
{
"id_region": "4",
"iso": "bg",
"mcc": "284",
"country": "Bulgaria",
"carriers": [
{
"carrier": "Comium",
"id_carrier": 75,
"brands": []
}
]
}
]
}
}
into smaller arrays, like this:
{[
"first_array" : [{
"id_region": "4",
"iso": "be",
"mcc": "206",
"country": "Belgium",
"carriers": [
{
"carrier": "Triton PCS",
"id_carrier": 68,
"brands": []
},
{
"carrier": "Beeline",
"id_carrier": 80,
"brands": []
}
]
]},
"second_array": [{
"id_region": "4",
"iso": "bg",
"mcc": "284",
"country": "Bulgaria",
"carriers": [{
"carrier": "Comium",
"id_carrier": 75,
"brands": []
}]
}],
"third_array": [{}],
"n_array": [{}]
]}
as you can see the new arrays has as the first branch, their country, and the structure is the same for their children.
I was thinking into do a recursive function, that get each value and with that validate with the keys, however, i don't know how to do the proper iteration and get each country as a new array with their respective children.
and also the array is dynamic, it can receive an array of n-objects