教程 - n8n表达式
高级
这是一个AI领域的自动化工作流,包含 25 个节点。主要使用 Set, SplitOut, ManualTrigger 等节点,结合人工智能技术实现智能自动化。 教程 - n8n表达式
前置要求
- •AI 服务 API Key(如 OpenAI、Anthropic 等)
使用的节点 (25)
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0"
},
"nodes": [
{
"id": "8d116e01-e52f-4a6b-85e4-bdbeb980f9f9",
"name": "开始教程",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-700,
300
],
"parameters": {},
"typeVersion": 1
},
{
"id": "67db85ae-7f2e-4823-867e-44709a01f6f3",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-960,
-100
],
"parameters": {
"color": 5,
"width": 640,
"height": 560,
"content": "# 教程 - 掌握 n8n 表达式"
},
"typeVersion": 1
},
{
"id": "d0e948fc-e924-4fbd-b7a3-caee971d16cf",
"name": "源数据",
"type": "n8n-nodes-base.set",
"position": [
-80,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "name",
"type": "string",
"value": "Alice"
},
{
"id": "67890",
"name": "age",
"type": "number",
"value": 30
},
{
"id": "abcde",
"name": "is_active",
"type": "boolean",
"value": true
},
{
"id": "fghij",
"name": "skills",
"type": "array",
"value": "[\"JavaScript\",\"Python\",\"n8n\"]"
},
{
"id": "klmno",
"name": "projects",
"type": "array",
"value": "[{\"name\":\"Project A\",\"status\":\"Done\"},{\"name\":\"Project B\",\"status\":\"In Progress\"}]"
},
{
"id": "pqrst",
"name": "contact",
"type": "object",
"value": "{\"email\":\"alice@example.com\",\"phone\":null}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c940a0b9-8982-4d61-b434-ca6f7ff46bc9",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-300,
-60
],
"parameters": {
"color": 7,
"width": 520,
"height": 520,
"content": "## 我们的数据源"
},
"typeVersion": 1
},
{
"id": "dcf9916f-a260-40fa-9503-2f9e5041b666",
"name": "1. 基础",
"type": "n8n-nodes-base.set",
"position": [
440,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "user_name",
"type": "string",
"value": "={{ $('Source Data').item.json.name }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "45b5e6a7-b588-4859-86e1-a6a73b67d837",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
240,
-120
],
"parameters": {
"color": 2,
"width": 500,
"height": 580,
"content": "## 第 1 课:访问简单值"
},
"typeVersion": 1
},
{
"id": "10c04c66-e07c-4ee5-8b2b-6d4de7c31c9f",
"name": "3. 处理数组",
"type": "n8n-nodes-base.set",
"position": [
1680,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "second_skill",
"type": "string",
"value": "={{ $('Source Data').last().json.skills[1] }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c4d1f2e2-bd7f-4c96-863d-45cc473d05a6",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1460,
-60
],
"parameters": {
"color": 4,
"width": 540,
"height": 520,
"content": "## 第 3 课:访问数组元素"
},
"typeVersion": 1
},
{
"id": "4b112b69-d29d-4963-9ee2-fe434bcbb2f7",
"name": "4. 深入探索",
"type": "n8n-nodes-base.set",
"position": [
2240,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "user_email",
"type": "string",
"value": "={{ $('Source Data').last().json.contact.email }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f157c7e6-ce9b-4049-a8b3-d309eec3048b",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
2020,
-20
],
"parameters": {
"color": 5,
"width": 540,
"height": 480,
"content": "## 第 4 课:访问嵌套数据"
},
"typeVersion": 1
},
{
"id": "ce9265d7-9bab-45d2-8fec-e50bc11c9760",
"name": "5. 组合操作",
"type": "n8n-nodes-base.set",
"position": [
2820,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "first_project_status",
"type": "string",
"value": "={{ $('Source Data').last().json.projects[0].status }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "8e612af5-7404-49b8-b908-44467b4f257a",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
2580,
-20
],
"parameters": {
"color": 6,
"width": 580,
"height": 480,
"content": "## 第 5 课:访问对象数组中的数据"
},
"typeVersion": 1
},
{
"id": "21ee04f0-1465-4166-bca9-e1b3a9dd21f6",
"name": "6. 一点魔法",
"type": "n8n-nodes-base.set",
"position": [
3420,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "name_in_caps",
"type": "string",
"value": "={{ $('Source Data').last().json.name.toUpperCase() }}"
},
{
"id": "67890",
"name": "age_in_dog_years",
"type": "number",
"value": "={{ Math.round($('Source Data').last().json.age / 7) }}"
},
{
"id": "abcde",
"name": "age_data_type",
"type": "string",
"value": "={{ typeof $('Source Data').last().json.age }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "6d307691-2789-467a-b005-5fb92b821a9b",
"name": "### 需要帮助?",
"type": "n8n-nodes-base.stickyNote",
"position": [
3180,
-60
],
"parameters": {
"color": 3,
"width": 580,
"height": 520,
"content": "## 第 6 课:一点魔法(JS 函数)"
},
"typeVersion": 1
},
{
"id": "14e8aec7-6681-49a9-a9fc-df14f2af2800",
"name": "9. “所有项目”视图",
"type": "n8n-nodes-base.set",
"position": [
5340,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "all_skills_string",
"type": "string",
"value": "={{ $('Split Out Skills').all().map(item => item.json.skills).join(', ') }}"
}
]
}
},
"executeOnce": true,
"typeVersion": 3.4
},
{
"id": "df1f2512-f89b-4602-973c-20bd5c9257a7",
"name": "## 试试看!",
"type": "n8n-nodes-base.stickyNote",
"position": [
4900,
-60
],
"parameters": {
"color": 5,
"width": 780,
"height": 520,
"content": "## 第 9 课:处理多个项目 (`$items` 和箭头函数)"
},
"typeVersion": 1
},
{
"id": "238fc0f7-1616-4fb0-8368-3eae3dcaa61b",
"name": "期末考试",
"type": "n8n-nodes-base.set",
"position": [
5920,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "final_summary",
"type": "string",
"value": "=User {{ $('2. The n8n Selectors').last().json.user_name_from_first }} is {{ $('Source Data').last().json.age }}.\n\nTheir best skill is {{ $('3. Working with Arrays').last().json.second_skill }}.\n\nTheir first project was {{ $('Source Data').last().json.projects[0].name }}, which is now {{ $('5. The Combo Move').last().json.first_project_status }}.\n\nAll skills: {{ $('9. The \"All Items\" View').last().json.all_skills_string }}."
}
]
}
},
"typeVersion": 3.4
},
{
"id": "2a2763a7-8190-410b-a257-1448de25d2f5",
"name": "GET 模型",
"type": "n8n-nodes-base.stickyNote",
"position": [
5700,
40
],
"parameters": {
"color": 6,
"width": 520,
"height": 420,
"content": "## 🎓 期末考试:综合运用"
},
"typeVersion": 1
},
{
"id": "0a3679ae-61cd-4745-b11f-5341a519a820",
"name": "2. n8n 选择器",
"type": "n8n-nodes-base.set",
"position": [
1060,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "user_name_from_first",
"type": "string",
"value": "={{ $('Source Data').last().json.name }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "4da0dce4-325c-4e91-af03-11e65f764f61",
"name": "## 1. 创建新的自定义 OpenAI 凭据",
"type": "n8n-nodes-base.stickyNote",
"position": [
760,
-160
],
"parameters": {
"width": 680,
"height": 620,
"content": "## 第 2 课:n8n 选择器 (`.first()`, `.last()`, `.all()`)"
},
"typeVersion": 1
},
{
"id": "f1327f83-1163-4879-8caa-06c5b8e2bbaa",
"name": "7. 检查对象",
"type": "n8n-nodes-base.set",
"position": [
3980,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "contact_keys",
"type": "array",
"value": "={{ Object.keys($('Source Data').last().json.contact) }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "29aad30e-74ed-48ff-b8c4-93cd31d34eea",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
3780,
-60
],
"parameters": {
"color": 2,
"width": 500,
"height": 520,
"content": "## 第 7 课:检查对象 (`Object.keys()`)"
},
"typeVersion": 1
},
{
"id": "11b91408-ab82-4d5e-9dc8-4b9d54e0a60f",
"name": "8. 实用函数",
"type": "n8n-nodes-base.set",
"position": [
4540,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "12345",
"name": "contact_as_string",
"type": "string",
"value": "={{ JSON.stringify($('Source Data').last().json.contact, null, 2) }}"
},
{
"id": "06003b65-7482-4d5a-b2c0-1794859ab461",
"name": "skills",
"type": "array",
"value": "={{ $('Source Data').last().json.skills }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "a0a39b92-f42e-4bb9-a601-bbc1fa5589b7",
"name": "便签 11",
"type": "n8n-nodes-base.stickyNote",
"position": [
4300,
-60
],
"parameters": {
"width": 580,
"height": 520,
"content": "## 第 8 课:实用函数 (`JSON.stringify()`)"
},
"typeVersion": 1
},
{
"id": "90c7d692-e2b8-4a89-8acb-138f9db1f316",
"name": "拆分技能",
"type": "n8n-nodes-base.splitOut",
"position": [
5120,
300
],
"parameters": {
"include": "allOtherFields",
"options": {},
"fieldToSplitOut": "skills"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Source Data": {
"main": [
[
{
"node": "1. The Basics",
"type": "main",
"index": 0
}
]
]
},
"1. The Basics": {
"main": [
[
{
"node": "2. The n8n Selectors",
"type": "main",
"index": 0
}
]
]
},
"Start Tutorial": {
"main": [
[
{
"node": "Source Data",
"type": "main",
"index": 0
}
]
]
},
"4. Going Deeper": {
"main": [
[
{
"node": "5. The Combo Move",
"type": "main",
"index": 0
}
]
]
},
"Split Out Skills": {
"main": [
[
{
"node": "9. The \"All Items\" View",
"type": "main",
"index": 0
}
]
]
},
"5. The Combo Move": {
"main": [
[
{
"node": "6. A Touch of Magic",
"type": "main",
"index": 0
}
]
]
},
"6. A Touch of Magic": {
"main": [
[
{
"node": "7. Inspecting Objects",
"type": "main",
"index": 0
}
]
]
},
"2. The n8n Selectors": {
"main": [
[
{
"node": "3. Working with Arrays",
"type": "main",
"index": 0
}
]
]
},
"8. Utility Functions": {
"main": [
[
{
"node": "Split Out Skills",
"type": "main",
"index": 0
}
]
]
},
"7. Inspecting Objects": {
"main": [
[
{
"node": "8. Utility Functions",
"type": "main",
"index": 0
}
]
]
},
"3. Working with Arrays": {
"main": [
[
{
"node": "4. Going Deeper",
"type": "main",
"index": 0
}
]
]
},
"9. The \"All Items\" View": {
"main": [
[
{
"node": "Final Exam",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用自动GPT和Gemini故障转移链构建弹性AI工作流
使用自动GPT和Gemini故障转移链构建弹性AI工作流
Set
Manual Trigger
Code
+4
9 节点Lucas Peyrin
人工智能
通过交互式动手教程学习API基础知识
通过交互式动手教程学习API基础知识
If
Set
Wait
+4
28 节点Lucas Peyrin
人工智能
教程 - n8n键盘快捷键
教程 - n8n键盘快捷键
If
Set
Manual Trigger
+3
45 节点Lucas Peyrin
人工智能
使用Gemini RAG管道构建文档专家聊天机器人
使用Gemini RAG管道构建文档专家聊天机器人
Set
Html
Filter
+16
48 节点Lucas Peyrin
内部知识库
通过交互式动手教程学习代码节点(JavaScript)基础知识
通过交互式动手教程学习代码节点(JavaScript)基础知识
Set
Code
Split Out
+2
12 节点Lucas Peyrin
杂项
学习数据同步:仓库库存审计教程
学习数据同步:仓库库存审计教程
Set
Split Out
Manual Trigger
+3
17 节点Lucas Peyrin
工程
工作流信息
难度等级
高级
节点数量25
分类1
节点类型4
作者
Lucas Peyrin
@lucaspeyrinInnovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline.
外部链接
在 n8n.io 查看 →
分享此工作流