Skip to content

Data structure#

ใน n8n ข้อมูลทั้งหมดที่ส่งผ่านระหว่าง nodes เป็น array ของ objects มีโครงสร้างดังนี้:

 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)
			}
		}
	},
]

Skipping the json key and array syntax

ตั้งแต่เวอร์ชัน 0.166.0 เป็นต้นไป เมื่อใช้ Function node หรือ Code node, n8n จะเพิ่ม json key โดยอัตโนมัติหากไม่มีอยู่ นอกจากนี้ยังจะห่อ items ของคุณใน array ([]) โดยอัตโนมัติหากจำเป็น สิ่งนี้ใช้ได้เฉพาะเมื่อใช้ Function หรือ Code nodes เท่านั้น เมื่อสร้าง nodes ของคุณเอง คุณยังคงต้องตรวจสอบให้แน่ใจว่า node ส่งคืนข้อมูลพร้อมกับ json key

Data item processing#

Nodes สามารถประมวลผลได้หลาย items

ตัวอย่างเช่น หากคุณตั้งค่า Trello node เป็น Create-Card และสร้าง expression ที่ตั้งค่า Name โดยใช้ property ที่ชื่อ name-input-value จากข้อมูลขาเข้า node จะสร้าง card สำหรับแต่ละ item โดยเลือก name-input-value ของ item ปัจจุบันเสมอ

ตัวอย่างเช่น input นี้จะสร้างสอง cards หนึ่งชื่อ test1 อีกอันชื่อ test2:

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