Skip to content

How n8n structures data#

Understanding how n8n structures and passes data between nodes is fundamental to building workflows. This guide covers both the data structure format and how data flows through your workflow.

Data structure#

在 n8n 中,节点之间传递的所有数据都是对象数组。它具有以下结构:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[
	{
		// 对于大多数数据:
		// 将每个项目包装在另一个对象中,键为 'json'
		"json": {
			// 示例数据
			"apple": "beets",
			"carrot": {
				"dill": 1
			}
		},
		// 对于二进制数据:
		// 将每个项目包装在另一个对象中,键为 'binary'
		"binary": {
			// 示例数据
			"apple-picture": {
				"data": "....", // Base64 编码的二进制数据(必需)
				"mimeType": "image/png", // 如果可能的话最好设置(可选)
				"fileExtension": "png", // 如果可能的话最好设置(可选)
				"fileName": "example.png", // 如果可能的话最好设置(可选)
			}
		}
	},
]

跳过 json 键和数组语法

从 0.166.0 开始,当使用函数节点或代码节点时,如果缺少 json 键,n8n 会自动添加它。如果需要,它还会自动将您的项目包装在数组([])中。这仅在使用函数或代码节点时适用。当构建您自己的节点时,您仍然必须确保节点返回带有 json 键的数据。

How data flows within nodes#

When you connect nodes in a workflow, data automatically passes from one node to the next.

Nodes process multiple items automatically. When a node receives an array of data items, it processes each item individually and performs the configured operation for each one.

For example, if you set the Trello node to Create-Card, and create an expression that sets Name using a property called name-input-value from the incoming data, the node creates a card for each item, always choosing the name-input-value of the current item.

For example, this input will create two cards. One named test1 the other one named test2:

1
2
3
4
5
6
7
8
[
	{
		"name-input-value": "test1"
	},
	{
		"name-input-value": "test2"
	}
]

Understand what you're mapping with drag and drop#

Data mapping maps the field path, and loads the field's value. For example, given the following data:

1
2
3
4
5
6
[
	{
		"fruit": "apples",
		"color": "green"
	}
]

You can map fruit by dragging and dropping fruit from the INPUT into the field where you want to use its value. This creates an expression, {{ $json.fruit }}. When the node iterates over input items, the value of the field becomes the value of fruit for each item.

Understand nested data#

Given the following data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[
  {
    "name": "First item",
    "nested": {
      "example-number-field": 1,
      "example-string-field": "apples"
    }
  },
  {
    "name": "Second item",
    "nested": {
      "example-number-field": 2,
      "example-string-field": "oranges"
    }
  }
]

n8n displays it in table form like this:

"Screenshot of a table in the INPUT panel. It includes a top level field named "nested." This field contains nested data, which is indicated in bold."