I’m working on an N8N workflow and I’m stuck on how to modify my JSON output. Right now, my output looks like this:
{
"data": [
{
"id": 21428
}
]
}
But what I really want is just the array inside, without the “data” key:
[
{
"id": 21428
}
]
I’ve tried using the ‘Split in Batches’ node to change my item list, but it didn’t work. Does anyone know a good way to do this in N8N? I’m not sure which nodes or settings I should use to get rid of that outer layer and just keep the array. Any help would be great!
Hey there! I’ve dealt with similar JSON extraction issues in N8N before. The Set node is your best friend here. After your node that outputs the JSON, add a Set node to your workflow. In the Set node, use the expression {{ $json.data }} as the value. This will grab just the array you want without the ‘data’ wrapper.
Make sure to name the output something like ‘json’ to keep it in JSON format. This approach is simple and works great for basic JSON manipulations. If you run into any issues, throw a Debug node after the Set node to check the output. It’s always helped me troubleshoot when things don’t work as expected.
Remember, N8N’s community forum is a goldmine for specific workflow questions if you need more help. Good luck with your workflow!
I’ve encountered this issue before in N8N. The Function node is perfect for this task. After your JSON output, add a Function node to your workflow. In the Function node, use this code:
return items.map(item => ({json: item.json.data[0]}));
This will extract just the array element you need from each item. It’s a flexible solution that works even if your data structure changes slightly.
If you’re not comfortable with JavaScript, the Set node method others mentioned is also good. But I find the Function node gives more control, especially for complex data transformations.
Remember to test your output with a Debug node. N8N’s visual interface makes it easy to spot any issues in your data flow.
yo, try the Function node! add it after ur JSON output and use this code:
return items.map(item => ({json: item.json.data[0]}));
this’ll grab just the array u want. it’s more flexible than Set node if ur data changes. test w/ Debug node to make sure it works. good luck!