How can I eliminate a JSON key from my output in N8N?

I’m attempting to modify the output of my N8N workflow to remove the outer JSON key. My goal is to return just the array of data without the surrounding structure. Here’s my current output format:

Current output:

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

I’m looking to extract it to achieve something like this:

Desired output:

[
   {
     "id": 21428
   }
]

I’ve experimented with changing my item list to use split output but haven’t had success. Can someone guide me on how to do this correctly?

Use the Set node instead - set operation to ‘keep only set fields’ and map your data array directly. Way simpler than code nodes. I just drag the data field from input to value field and it automatically strips the outer JSON wrapper.

Use a Code node with a simple JavaScript expression to extract the array value. Add this: return items[0].json.data.map(item => ({json: item})); This grabs the data array from your JSON and transforms it into N8N’s expected format, ditching that outer wrapper. I hit this same problem last month with API responses that had weird nesting. N8N wants each item to have a json property, so you map over your array and wrap each element. Drop this Code node right after whatever’s creating your nested output.

The Function Item node is perfect for this. Set it to run once for all items and use return $input.all()[0].json.data as your expression. This grabs the data array from the first item and N8N automatically formats it as individual items. I’ve done this tons of times with APIs that wrap responses in containers. Function Item is way easier than the Code node - you don’t have to mess with json property mapping since N8N handles the array conversion automatically.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.