How to extract array from JSON wrapper object in N8N workflow

I’m working with N8N and need help extracting an array from a JSON object that’s wrapped with an outer key. My workflow currently produces JSON with a wrapper object, but I need just the inner array for my endpoint.

Current structure I’m getting:

{
  "results": [
    {
      "userId": 12345
    }
  ]
}

What I need to achieve:

[
  {
    "userId": 12345
  }
]

Basically I want to unwrap the array from the “results” key and return only the array contents. I tried using the split output option in the item list settings but that didn’t work for me. What’s the proper way to handle this kind of JSON transformation in N8N? I need to process all items in the array, not just single values.

You can achieve this using the Code node instead of Function node. In the Code node, add this JavaScript snippet: $input.all()[0].json.results.forEach(item => $return.push({json: item})); This approach directly iterates through your results array and pushes each item to the output with proper N8N formatting. I found this method more reliable than using map functions when dealing with wrapped arrays, especially when the source data structure might vary. The Code node gives you better control over the output format and handles edge cases like empty arrays more gracefully than other transformation methods.

honestly the easiest way is just using the set node with an expression. add a set node and set the value to {{$json.results}} and thats it. no need for complex javascript or code nodes unless your doing something more complicated. this method directly outputs the unwrapped array without extra formatting hassles.

The most straightforward approach is using a Function node with a simple JavaScript expression. Add a Function node after your current workflow step and use this code: return items[0].json.results.map(item => ({json: item})); This will extract the array from the results wrapper and properly format it for N8N’s item structure. Make sure you’re working with the first item if your previous node outputs multiple items, otherwise adjust the index accordingly. I’ve used this method extensively when dealing with API responses that wrap arrays in metadata objects and it handles multiple array items without issues.