n8n-expression-syntax by czlonkowski/n8n-skills
npx skills add https://github.com/czlonkowski/n8n-skills --skill n8n-expression-syntax在 n8n 工作流中编写正确表达式的专家指南。
n8n 中的所有动态内容都使用 双花括号 :
{{表达式}}
示例 :
✅ {{$json.email}}
✅ {{$json.body.name}}
✅ {{$node["HTTP Request"].json.data}}
❌ $json.email (没有花括号 - 被视为字面文本)
❌ {$json.email} (单花括号 - 无效)
访问当前节点的数据:
{{$json.字段名}}
{{$json['带空格的字段']}}
{{$json.嵌套属性.属性}}
{{$json.items[0].name}}
访问任何先前节点的数据:
{{$node["节点名称"].json.字段名}}
{{$node["HTTP Request"].json.data}}
{{$node["Webhook"].json.body.email}}
重要提示 :
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
访问当前日期/时间:
{{$now}}
{{$now.toFormat('yyyy-MM-dd')}}
{{$now.toFormat('HH:mm:ss')}}
{{$now.plus({days: 7})}}
访问环境变量:
{{$env.API_KEY}}
{{$env.DATABASE_URL}}
最常见的错误 :Webhook 数据 不 在根目录下!
{
"headers": {...},
"params": {...},
"query": {...},
"body": { // ⚠️ 用户数据在这里!
"name": "John",
"email": "john@example.com",
"message": "Hello"
}
}
❌ 错误:{{$json.name}}
❌ 错误:{{$json.email}}
✅ 正确:{{$json.body.name}}
✅ 正确:{{$json.body.email}}
✅ 正确:{{$json.body.message}}
原因 :Webhook 节点将传入的数据包装在 .body 属性下,以保留 headers、params 和 query 参数。
// 简单嵌套
{{$json.user.email}}
// 数组访问
{{$json.data[0].name}}
{{$json.items[0].id}}
// 使用方括号表示法处理空格
{{$json['字段名']}}
{{$json['用户数据']['名字']}}
// 节点名称不含空格
{{$node["Set"].json.value}}
// 节点名称含空格(常见!)
{{$node["HTTP Request"].json.data}}
{{$node["Respond to Webhook"].json.message}}
// Webhook 节点
{{$node["Webhook"].json.body.email}}
// 连接(自动)
Hello {{$json.body.name}}!
// 在 URL 中
https://api.example.com/users/{{$json.body.user_id}}
// 在对象属性中
{
"name": "={{$json.body.name}}",
"email": "={{$json.body.email}}"
}
代码节点使用 直接的 JavaScript 访问 ,而不是表达式!
// ❌ 在代码节点中错误
const email = '={{$json.email}}';
const name = '{{$json.body.name}}';
// ✅ 在代码节点中正确
const email = $json.email;
const name = $json.body.name;
// 或使用代码节点 API
const email = $input.item.json.email;
const allItems = $input.all();
// ❌ 错误
path: "{{$json.user_id}}/webhook"
// ✅ 正确
path: "user-webhook" // 仅限静态路径
// ❌ 错误
apiKey: "={{$env.API_KEY}}"
// ✅ 正确
使用 n8n 凭证系统,而非表达式
表达式 必须 用双花括号包裹。
❌ $json.field
✅ {{$json.field}}
字段或节点名称包含空格时,需要使用 方括号表示法 :
❌ {{$json.field name}}
✅ {{$json['field name']}}
❌ {{$node.HTTP Request.json}}
✅ {{$node["HTTP Request"].json}}
节点引用 区分大小写 :
❌ {{$node["http request"].json}} // 小写
❌ {{$node["Http Request"].json}} // 错误的大小写
✅ {{$node["HTTP Request"].json}} // 精确匹配
不要双重包裹表达式:
❌ {{{$json.field}}}
✅ {{$json.field}}
有关完整的错误目录及修复方法,请参阅 COMMON_MISTAKES.md
| 错误 | 修复 |
|---|---|
$json.field | {{$json.field}} |
{{$json.field name}} | {{$json['field name']}} |
{{$node.HTTP Request}} | {{$node["HTTP Request"]}} |
{{{$json.field}}} | {{$json.field}} |
{{$json.name}} (webhook) | {{$json.body.name}} |
'={{$json.email}}' (Code node) | $json.email |
有关真实工作流示例,请参阅 EXAMPLES.md
Webhook 接收 :
{
"body": {
"name": "John Doe",
"email": "john@example.com",
"message": "Hello!"
}
}
在 Slack 节点的文本字段中 :
新表单提交!
姓名:{{$json.body.name}}
邮箱:{{$json.body.email}}
消息:{{$json.body.message}}
HTTP 请求返回 :
{
"data": {
"items": [
{"name": "Product 1", "price": 29.99}
]
}
}
在邮件节点中 (引用 HTTP 请求):
产品:{{$node["HTTP Request"].json.data.items[0].name}}
价格:${{$node["HTTP Request"].json.data.items[0].price}}
// 当前日期
{{$now.toFormat('yyyy-MM-dd')}}
// 结果:2025-10-20
// 时间
{{$now.toFormat('HH:mm:ss')}}
// 结果:14:30:45
// 完整日期时间
{{$now.toFormat('yyyy-MM-dd HH:mm')}}
// 结果:2025-10-20 14:30
// 第一项
{{$json.users[0].email}}
// 数组长度
{{$json.users.length}}
// 最后一项
{{$json.users[$json.users.length - 1].name}}
// 点表示法(无空格)
{{$json.user.email}}
// 方括号表示法(含空格或动态)
{{$json['user data'].email}}
// 连接(自动)
Hello {{$json.name}}!
// 字符串方法
{{$json.email.toLowerCase()}}
{{$json.name.toUpperCase()}}
// 直接使用
{{$json.price}}
// 数学运算
{{$json.price * 1.1}} // 增加 10%
{{$json.quantity + 5}}
// 三元运算符
{{$json.status === 'active' ? 'Active User' : 'Inactive User'}}
// 默认值
{{$json.email || 'no-email@example.com'}}
// 添加天数
{{$now.plus({days: 7}).toFormat('yyyy-MM-dd')}}
// 减去小时
{{$now.minus({hours: 24}).toISO()}}
// 设置特定日期
{{DateTime.fromISO('2025-12-25').toFormat('MMMM dd, yyyy')}}
// 子字符串
{{$json.email.substring(0, 5)}}
// 替换
{{$json.message.replace('old', 'new')}}
// 分割与连接
{{$json.tags.split(',').join(', ')}}
"无法读取未定义的属性 'X'" → 父对象不存在 → 检查你的数据路径
"X 不是一个函数" → 尝试在非函数上调用方法 → 检查变量类型
表达式显示为字面文本 → 缺少 {{ }} → 添加花括号
字符串 :
.toLowerCase(), .toUpperCase().trim(), .replace(), .substring().split(), .includes()数组 :
.length, .map(), .filter().find(), .join(), .slice()DateTime (Luxon):
.toFormat(), .toISO(), .toLocal().plus(), .minus(), .set()数字 :
.toFixed(), .toString()+, -, *, /, %.body 引用 webhook 数据基本规则 :
.body 下最常见的错误 :
{{$json.name}} → 使用 {{$json.body.name}}{{$json.email}} → 使用 $json.email{{$node.HTTP Request}} → 使用 {{$node["HTTP Request"]}}更多详情,请参阅:
需要帮助? 参考 n8n 表达式文档或使用 n8n-mcp 验证工具来检查你的表达式。
每周安装量
1.3K
仓库
GitHub 星标数
3.7K
首次出现
Jan 20, 2026
安全审计
安装于
opencode1.2K
gemini-cli1.2K
codex1.1K
github-copilot1.1K
cursor1.0K
amp1.0K
Expert guide for writing correct n8n expressions in workflows.
All dynamic content in n8n uses double curly braces :
{{expression}}
Examples :
✅ {{$json.email}}
✅ {{$json.body.name}}
✅ {{$node["HTTP Request"].json.data}}
❌ $json.email (no braces - treated as literal text)
❌ {$json.email} (single braces - invalid)
Access data from the current node:
{{$json.fieldName}}
{{$json['field with spaces']}}
{{$json.nested.property}}
{{$json.items[0].name}}
Access data from any previous node:
{{$node["Node Name"].json.fieldName}}
{{$node["HTTP Request"].json.data}}
{{$node["Webhook"].json.body.email}}
Important :
Access current date/time:
{{$now}}
{{$now.toFormat('yyyy-MM-dd')}}
{{$now.toFormat('HH:mm:ss')}}
{{$now.plus({days: 7})}}
Access environment variables:
{{$env.API_KEY}}
{{$env.DATABASE_URL}}
Most Common Mistake : Webhook data is NOT at the root!
{
"headers": {...},
"params": {...},
"query": {...},
"body": { // ⚠️ USER DATA IS HERE!
"name": "John",
"email": "john@example.com",
"message": "Hello"
}
}
❌ WRONG: {{$json.name}}
❌ WRONG: {{$json.email}}
✅ CORRECT: {{$json.body.name}}
✅ CORRECT: {{$json.body.email}}
✅ CORRECT: {{$json.body.message}}
Why : Webhook node wraps incoming data under .body property to preserve headers, params, and query parameters.
// Simple nesting
{{$json.user.email}}
// Array access
{{$json.data[0].name}}
{{$json.items[0].id}}
// Bracket notation for spaces
{{$json['field name']}}
{{$json['user data']['first name']}}
// Node without spaces
{{$node["Set"].json.value}}
// Node with spaces (common!)
{{$node["HTTP Request"].json.data}}
{{$node["Respond to Webhook"].json.message}}
// Webhook node
{{$node["Webhook"].json.body.email}}
// Concatenation (automatic)
Hello {{$json.body.name}}!
// In URLs
https://api.example.com/users/{{$json.body.user_id}}
// In object properties
{
"name": "={{$json.body.name}}",
"email": "={{$json.body.email}}"
}
Code nodes use direct JavaScript access , NOT expressions!
// ❌ WRONG in Code node
const email = '={{$json.email}}';
const name = '{{$json.body.name}}';
// ✅ CORRECT in Code node
const email = $json.email;
const name = $json.body.name;
// Or using Code node API
const email = $input.item.json.email;
const allItems = $input.all();
// ❌ WRONG
path: "{{$json.user_id}}/webhook"
// ✅ CORRECT
path: "user-webhook" // Static paths only
// ❌ WRONG
apiKey: "={{$env.API_KEY}}"
// ✅ CORRECT
Use n8n credential system, not expressions
Expressions must be wrapped in double curly braces.
❌ $json.field
✅ {{$json.field}}
Field or node names with spaces require bracket notation :
❌ {{$json.field name}}
✅ {{$json['field name']}}
❌ {{$node.HTTP Request.json}}
✅ {{$node["HTTP Request"].json}}
Node references are case-sensitive :
❌ {{$node["http request"].json}} // lowercase
❌ {{$node["Http Request"].json}} // wrong case
✅ {{$node["HTTP Request"].json}} // exact match
Don't double-wrap expressions:
❌ {{{$json.field}}}
✅ {{$json.field}}
For complete error catalog with fixes, see COMMON_MISTAKES.md
| Mistake | Fix |
|---|---|
$json.field | {{$json.field}} |
{{$json.field name}} | {{$json['field name']}} |
{{$node.HTTP Request}} | {{$node["HTTP Request"]}} |
{{{$json.field}}} | {{$json.field}} |
For real workflow examples, see EXAMPLES.md
Webhook receives :
{
"body": {
"name": "John Doe",
"email": "john@example.com",
"message": "Hello!"
}
}
In Slack node text field :
New form submission!
Name: {{$json.body.name}}
Email: {{$json.body.email}}
Message: {{$json.body.message}}
HTTP Request returns :
{
"data": {
"items": [
{"name": "Product 1", "price": 29.99}
]
}
}
In Email node (reference HTTP Request):
Product: {{$node["HTTP Request"].json.data.items[0].name}}
Price: ${{$node["HTTP Request"].json.data.items[0].price}}
// Current date
{{$now.toFormat('yyyy-MM-dd')}}
// Result: 2025-10-20
// Time
{{$now.toFormat('HH:mm:ss')}}
// Result: 14:30:45
// Full datetime
{{$now.toFormat('yyyy-MM-dd HH:mm')}}
// Result: 2025-10-20 14:30
// First item
{{$json.users[0].email}}
// Array length
{{$json.users.length}}
// Last item
{{$json.users[$json.users.length - 1].name}}
// Dot notation (no spaces)
{{$json.user.email}}
// Bracket notation (with spaces or dynamic)
{{$json['user data'].email}}
// Concatenation (automatic)
Hello {{$json.name}}!
// String methods
{{$json.email.toLowerCase()}}
{{$json.name.toUpperCase()}}
// Direct use
{{$json.price}}
// Math operations
{{$json.price * 1.1}} // Add 10%
{{$json.quantity + 5}}
// Ternary operator
{{$json.status === 'active' ? 'Active User' : 'Inactive User'}}
// Default values
{{$json.email || 'no-email@example.com'}}
// Add days
{{$now.plus({days: 7}).toFormat('yyyy-MM-dd')}}
// Subtract hours
{{$now.minus({hours: 24}).toISO()}}
// Set specific date
{{DateTime.fromISO('2025-12-25').toFormat('MMMM dd, yyyy')}}
// Substring
{{$json.email.substring(0, 5)}}
// Replace
{{$json.message.replace('old', 'new')}}
// Split and join
{{$json.tags.split(',').join(', ')}}
"Cannot read property 'X' of undefined" → Parent object doesn't exist → Check your data path
"X is not a function" → Trying to call method on non-function → Check variable type
Expression shows as literal text → Missing {{ }} → Add curly braces
String :
.toLowerCase(), .toUpperCase().trim(), .replace(), .substring().split(), .includes()Array :
.length, .map(), .filter().find(), .join(), .slice()DateTime (Luxon):
.toFormat(), .toISO(), .toLocal().plus(), .minus(), .set()Number :
.toFixed(), .toString()+, -, *, /, %.bodyEssential Rules :
.bodyMost Common Mistakes :
{{$json.name}} in webhooks → Use {{$json.body.name}}{{$json.email}} in Code → Use $json.email{{$node.HTTP Request}} → Use {{$node["HTTP Request"]}}For more details, see:
Need Help? Reference the n8n expression documentation or use n8n-mcp validation tools to check your expressions.
Weekly Installs
1.3K
Repository
GitHub Stars
3.7K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode1.2K
gemini-cli1.2K
codex1.1K
github-copilot1.1K
cursor1.0K
amp1.0K
99,500 周安装
{{$json.name}} (webhook) | {{$json.body.name}} |
'={{$json.email}}' (Code node) | $json.email |