How to combine objects into an array by their parent property?

Hey!
How to convert data from this format:

In this:

[
{
"lable": "Blue",
"value": "a",
"children": [
{
"lable": "One",
"value": "v"
},
{
"lable": "Two",
"value": "w"
}
]
},
{
"lable": "Green",
"value": "b",
"children": [
{
"lable": "Three",
"value": "x"
}
]
},
{
"lable": "Purple",
"value": "c",
"children": [
{
"lable": "Four",
"value": "y"
},
{
"lable": "Five",
"value": "z"
}
]
}
]

Hi @Roket, since you want to convert five input items into three output items, you’d need to use the Function node here. You could then write some custom JavaScript code to filter the items in the required way (keep in mind how n8n expects the data to be structured).