Skip to content

数据结构(Data structure)#

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

🌐 In n8n, all data passed between nodes is an array of objects. It has the following structure:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[
	{
		// For most data:
		// Wrap each item in another object, with the key 'json'
		"json": {
			// Example data
			"apple": "beets",
			"carrot": {
				"dill": 1
			}
		},
		// For binary data:
		// Wrap each item in another object, with the key 'binary'
		"binary": {
			// Example data
			"apple-picture": {
				"data": "....", // Base64 encoded binary data (required)
				"mimeType": "image/png", // Best practice to set if possible (optional)
				"fileExtension": "png", // Best practice to set if possible (optional)
				"fileName": "example.png", // Best practice to set if possible (optional)
			}
		}
	},
]

跳过 json 键和数组语法

从 0.166.0 版本开始,在使用 Function 节点或 Code 节点时,如果缺少 json 键,n8n 会自动添加它。如果需要,它还会自动将你的项目封装在一个数组([])中。只有在使用 Function 或 Code 节点时才会这样。当你构建自己的节点时,仍然必须确保节点返回的数据包含 json 键。

数据项处理(Data item processing)#

Nodes can process multiple items.

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"
	}
]