跳转至

编辑字段 (Set)#

使用编辑字段节点设置工作流数据。此节点可以设置新数据并覆盖已存在的数据。在需要从前一个节点接收入站数据的工作流中,此节点至关重要,例如向 Google Sheets 或数据库插入值时。

节点参数#

这些是编辑字段节点中可用的设置和选项。

模式#

您可以使用手动映射通过 GUI 编辑字段,或使用 JSON 输出编写 n8n 添加到输入数据的 JSON。

要设置的字段#

如果您选择模式 > 手动映射,您可以通过从 INPUT 中拖放值来配置字段。

拖放值时的默认行为是:

  • n8n 将值的名称设置为字段名称。
  • 字段值包含一个访问该值的表达式。

如果您不想使用表达式:

  1. 将鼠标悬停在字段上。n8n 显示 固定 | 表达式切换。
  2. 选择固定

您可以对字段的名称和值都这样做。

显示拖放操作以及将字段更改为固定的 gif

仅保留设置的字段#

启用此选项以丢弃任何您在要设置的字段中未使用的输入数据。

包含在输出中#

选择在节点的输出数据中包含哪些输入数据。

节点选项#

使用这些选项来自定义节点的行为。

包含二进制数据#

如果输入数据包含二进制数据,请选择是否在编辑字段节点的输出数据中包含它。

忽略类型转换错误#

仅限手动映射。

启用此选项允许 n8n 在映射字段时忽略某些数据类型错误。

支持点记法#

默认情况下,n8n 支持点记法。

例如,在使用手动映射时,节点遵循 名称字段的点记法。这意味着如果您在名称字段中将名称设置为 number.one,在字段中将值设置为 20,生成的 JSON 是:

1
{ "number": { "one": 20} }

您可以通过选择添加选项 > 支持点记法,并将点记法字段设置为关闭来阻止此行为。现在生成的 JSON 是:

1
{ "number.one": 20 }

模板和示例#

Creating an API endpoint

by Jonathan

View template details
Scrape and summarize webpages with AI

by n8n Team

View template details
Very quick quickstart

by Deborah

View template details
Browse 编辑字段 (Set) integration templates, or search all templates

JSON 输出模式中的数组和表达式#

在创建 JSON 输出时,您可以使用数组和表达式。

例如,给定由客户数据存储节点生成的此输入数据:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[
  {
    "id": "23423532",
    "name": "Jay Gatsby",
    "email": "[email protected]",
    "notes": "Keeps asking about a green light??",
    "country": "US",
    "created": "1925-04-10"
  },
  {
    "id": "23423533",
    "name": "José Arcadio Buendía",
    "email": "[email protected]",
    "notes": "Lots of people named after him. Very confusing",
    "country": "CO",
    "created": "1967-05-05"
  },
  {
    "id": "23423534",
    "name": "Max Sendak",
    "email": "[email protected]",
    "notes": "Keeps rolling his terrible eyes",
    "country": "US",
    "created": "1963-04-09"
  },
  {
    "id": "23423535",
    "name": "Zaphod Beeblebrox",
    "email": "[email protected]",
    "notes": "Felt like I was talking to more than one person",
    "country": null,
    "created": "1979-10-12"
  },
  {
    "id": "23423536",
    "name": "Edmund Pevensie",
    "email": "[email protected]",
    "notes": "Passionate sailor",
    "country": "UK",
    "created": "1950-10-16"
  }
]

JSON 输出字段中添加以下 JSON,将包含在输出中设置为所有输入字段

1
2
3
4
5
6
7
8
9
{
  "newKey": "new value",
  "array": [{{ $json.id }},"{{ $json.name }}"],
  "object": {
    "innerKey1": "new value",
    "innerKey2": "{{ $json.id }}",
    "innerKey3": "{{ $json.name }}",
 }
}

您得到此输出:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
[
  {
    "id": "23423532",
    "name": "Jay Gatsby",
    "email": "[email protected]",
    "notes": "Keeps asking about a green light??",
    "country": "US",
    "created": "1925-04-10",
    "newKey": "new value",
    "array": [
      23423532,
      "Jay Gatsby"
    ],
    "object": {
      "innerKey1": "new value",
      "innerKey2": "23423532",
      "innerKey3": "Jay Gatsby"
    }
  },
  {
    "id": "23423533",
    "name": "José Arcadio Buendía",
    "email": "[email protected]",
    "notes": "Lots of people named after him. Very confusing",
    "country": "CO",
    "created": "1967-05-05",
    "newKey": "new value",
    "array": [
      23423533,
      "José Arcadio Buendía"
    ],
    "object": {
      "innerKey1": "new value",
      "innerKey2": "23423533",
      "innerKey3": "José Arcadio Buendía"
    }
  },
  {
    "id": "23423534",
    "name": "Max Sendak",
    "email": "[email protected]",
    "notes": "Keeps rolling his terrible eyes",
    "country": "US",
    "created": "1963-04-09",
    "newKey": "new value",
    "array": [
      23423534,
      "Max Sendak"
    ],
    "object": {
      "innerKey1": "new value",
      "innerKey2": "23423534",
      "innerKey3": "Max Sendak"
    }
  },
  {
    "id": "23423535",
    "name": "Zaphod Beeblebrox",
    "email": "[email protected]",
    "notes": "Felt like I was talking to more than one person",
    "country": null,
    "created": "1979-10-12",
    "newKey": "new value",
    "array": [
      23423535,
      "Zaphod Beeblebrox"
    ],
    "object": {
      "innerKey1": "new value",
      "innerKey2": "23423535",
      "innerKey3": "Zaphod Beeblebrox"
    }
  },
  {
    "id": "23423536",
    "name": "Edmund Pevensie",
    "email": "[email protected]",
    "notes": "Passionate sailor",
    "country": "UK",
    "created": "1950-10-16",
    "newKey": "new value",
    "array": [
      23423536,
      "Edmund Pevensie"
    ],
    "object": {
      "innerKey1": "new value",
      "innerKey2": "23423536",
      "innerKey3": "Edmund Pevensie"
    }
  }
]
此页面是否
💬 微信

🚀 与作者交流

关注公众号
n8n实战笔记公众号
n8n实战笔记
📚 教程 💡 案例 🔧 技巧
添加微信
添加作者微信
1对1 专业指导
⚡ 快答 🎯 定制 🚀 支持