How to strip outer JSON key in N8N workflow output?

Hey everyone, I’m stuck with an N8N workflow problem. I need to remove the outer JSON key from my output. Right now, I’m getting this:

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

But I want it to look like this:

[
   {
     "id": 21428
   }
]

I’ve tried using the Split In Batches node and messing with the Item Lists, but no luck so far. Any ideas on how to strip that outer ‘data’ key? I’m not looking to get just one value, I need the whole array. Thanks for any help!

I encountered a similar issue in one of my N8N workflows. The Function node proved to be quite effective for this task. You can use it to directly manipulate the JSON structure. Here’s a simple script that should work:

return items.map(item => item.json.data[0]);

This will extract the contents of the ‘data’ array and return it as the new output. After applying this, your JSON should be in the desired format. Remember to place the Function node after the node that’s generating your current output. If you’re dealing with multiple items, you might need to adjust the script slightly. Let me know if you need any clarification on implementing this solution.

I’ve dealt with this exact issue before, and I found a neat workaround using the JSON Parse node. Here’s what you can do:

  1. After your current output, add a JSON Parse node.
  2. In the JSON Parse node, set the ‘Property Name’ to ‘data’.
  3. Leave the ‘Property Value’ blank.

This effectively tells N8N to parse only the ‘data’ property of your JSON, discarding the outer structure. The output should then be your desired array format.

If that doesn’t work for some reason, you could also try using a Code node with a simple JavaScript function:

return JSON.parse(JSON.stringify(items[0].json)).data;

This parses your entire JSON structure, then immediately extracts just the ‘data’ property.

Both methods should give you the clean array output you’re looking for. Good luck with your workflow!

hey there! have u tried using the Set node? you can set the value to = {{$json.data}} which should grab just the array inside. then use JSON node to make sure its formatted right. hope that helps! lmk if u need more info