Passing the whole output data from a previous node to another node

Hi Support Team,

I’m encountering an issue while trying to pass the entire output of a node to another node in JSON format in an n8n workflow. Here are the details:

  • Workflow Context:
    I have a node named code to extract variants and create the json2, which I believe outputs an array of objects.
    However, when I use the following expression:
{{ JSON.stringify($node["code to extract variants and create the json2"].json) }}

It only includes the first item in the array, rather than the entire array of objects.

I expect the output to be something like this:

[
  {
    "title": "Apple 98-1",
    "sku": "apple-ninety-eight-1",
    "price": 19.99,
    "qty": 999,
    "variations": [
      { "variant": "Quantity", "option": "1", "key": "", "variantType": "D" }
    ]
  },
  {
    "title": "Apple 98-2",
    "sku": "apple-ninety-eight-2",
    "price": 19.99,
    "qty": 999,
    "variations": [
      { "variant": "Quantity", "option": "2", "key": "", "variantType": "D" }
    ]
  }
]

I only get this:

{
    "title": "Apple 98-1",
    "sku": "apple-ninety-eight-1",
    "price": 19.99,
    "qty": 999,
    "variations": [
      { "variant": "Quantity", "option": "1", "key": "", "variantType": "D" }
    ]
}
  • Debug Steps Taken:
    1. I confirmed that the output of the node in the Debug Panel seems correct (i.e., it outputs multiple items or an array).
    2. I tried different expressions, including:
{{ JSON.stringify($node["code to extract variants and create the json2"].json.map(item => item)) }}

But this returned undefined.
3. I also attempted using a Function Node to aggregate outputs, but it didn’t resolve the issue.

Could you help me understand how to reference the full output of the node in JSON format so that it includes all items, not just the first one?

Thanks in advance for your assistance!

Best regards,

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @josephavetti , I do not follow why you use JSON.stringify(). The output of that is a string. The data between nodes are passed as per Data structure | n8n Docs.

You never mentioned what data you have as an output of “code to extract variants and create the json2” node.

1 Like

Hi @josephavetti!

The output data of a node can contain multiple elements, which n8n refers to as “items”. To combine an array of items into a single element, you can use the “Aggregate” node or use an expression like this: {{ $('Your Node').all() }}

The following workflow illustrates both approaches.

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