I am getting below json array as and i want to remove the child node "n":[] - when it is empty. (PHP)
INPUT:
[
{
"level": 1,
"id": "101",
"n": [
{
"level": 2,
"id": "102",
"n": [
]
}
]
},
{
"level": 1,
"id": "103",
"n": [
{
"level": 2,
"id": "104",
"n": [
]
},
{
"level": 2,
"id": "105",
"n": [
{
"level": 3,
"id": "106",
"n": [
]
},
{
"level": 3,
"id": "107",
"n": [
{
"level": 4,
"id": "108",
"n": [
{
"level": 5,
"id": "109",
"n": [
]
}
]
}
]
}
]
}
]
},
{
"level": 1,
"id": "110",
"n": [
{
"level": 2,
"id": "111",
"n": [
{
"level": 3,
"id": "112",
"n": [
]
}
]
},
{
"level": 2,
"id": "113",
"n": [
{
"level": 3,
"id": "114",
"n": [
{
"level": 4,
"id": "115",
"n": [
]
}
]
},
{
"level": 3,
"id": "116",
"n": [
{
"level": 4,
"id": "117",
"n": [
]
},
{
"level": 4,
"id": "118",
"n": [
{
"level": 5,
"id": "119",
"n": [
]
},
{
"level": 5,
"id": "120",
"n": [
]
}
]
}
]
}
]
}
]
}
]
OUTPUT:
[
{
"level": 1,
"id": "101",
"n": [
{
"level": 2,
"id": "102"
}
]
},
{
"level": 1,
"id": "103",
"n": [
{
"level": 2,
"id": "104"
},
{
"level": 2,
"id": "105",
"n": [
{
"level": 3,
"id": "106"
},
{
"level": 3,
"id": "107",
"n": [
{
"level": 4,
"id": "108",
"n": [
{
"level": 5,
"id": "109"
}
]
}
]
}
]
}
]
},
{
"level": 1,
"id": "110",
"n": [
{
"level": 2,
"id": "111",
"n": [
{
"level": 3,
"id": "112"
}
]
},
{
"level": 2,
"id": "113",
"n": [
{
"level": 3,
"id": "114",
"n": [
{
"level": 4,
"id": "115"
}
]
},
{
"level": 3,
"id": "116",
"n": [
{
"level": 4,
"id": "117"
},
{
"level": 4,
"id": "118",
"n": [
{
"level": 5,
"id": "119"
},
{
"level": 5,
"id": "120"
}
]
}
]
}
]
}
]
}
]
All the ,"n":[] removed from the json array. Please help me with some PHP code to get the output from that above input.