How to strip JSON wrapper from N8N output?

Hey everyone! I’m kinda stuck with my N8N workflow. I’ve got this JSON output that has a ‘data’ wrapper I don’t want. Here’s what I’m getting now:

{
  "data": [
    {
      "id": 21428
    }
  ]
}

But what I really need is just the array inside, like this:

[
  {
    "id": 21428
  }
]

I’ve been messing around with the item list and tried splitting the output, but no luck so far. Any ideas on how to strip off that outer layer? I’m not looking to grab just one value - I need the whole array minus the wrapper. Thanks for any help!

I’ve found a straightforward way to handle this in N8N using the ‘Set’ node. After your current output, add a ‘Set’ node to your workflow. In this node, create a new item with a value that directly references the ‘data’ array from your input.

Configure the ‘Set’ node as follows:

  • Keep Only Set: Yes
  • Value: =input.item.json.data

This approach effectively strips the outer wrapper and gives you just the array you need. It’s a clean solution that doesn’t require writing any custom code.

If you’re processing multiple items, you might need to adjust this slightly, but for most cases, this method should work seamlessly. Let me know if you need any clarification on implementing this in your workflow.

I’ve encountered this issue before in my N8N workflows, and there’s a simple solution using the ‘Function’ node. Here’s what worked for me:

  1. Add a ‘Function’ node after your current output.
  2. In the Function node, use this JavaScript code:
const input = items[0].json;
return input.data;

This code assumes your data is in the first item of the input. It extracts the ‘data’ property and returns it directly.

If you’re dealing with multiple items, you might need to map over them:

return items.map(item => item.json.data).flat();

This approach has consistently worked for me to strip off unwanted JSON wrappers. Hope it helps solve your problem too!

hey olivia, try addin the JSON node after ur output. set the Operation to Get Value with key data. it strips off the wrapper n gives u just the array. works real good. ping me if needed!