| name | n8n-expression-syntax |
| description | Write correct n8n expressions in workflow fields. Use when writing expressions, accessing data from previous nodes, using $json, $input, $node references, JavaScript in expressions, date/time formatting, or debugging expression errors. Use when this capability is needed. |
| metadata | {"author":"fazer-ai"} |
n8n Expression Syntax
Expert guide for writing correct n8n expressions in workflows.
Based on n8n-skills by Romuald Członkowski
Expression Basics
n8n expressions use {{ }} syntax and are evaluated at runtime:
{{ $json.fieldName }}
{{ $json.user.email }}
{{ $json.items[0].name }}
Data References
Current Node Data
{{ $json.propertyName }}
{{ $binary.data.fileName }}
{{ $itemIndex }}
Previous Node Data
{{ $node["Node Name"].json.field }}
{{ $input.item.json.field }}
{{ $node["HTTP Request"].first().json.data }}
{{ $node["Webhook"].all() }}
Execution Context
{{ $workflow.id }}
{{ $workflow.name }}
{{ $execution.id }}
{{ $execution.resumeUrl }}
{{ $now }}
{{ $today }}
Common Patterns
Webhook Data Access
CRITICAL: Webhook data is nested under .body:
{{ $json.message }}
{{ $json.body.message }}
{{ $json.headers["content-type"] }}
{{ $json.query.paramName }}
Conditional Expressions
{{ $json.status === "active" ? "Yes" : "No" }}
{{ $json.name ?? "Unknown" }}
{{ $json.user?.profile?.avatar }}
String Operations
{{ `Hello ${$json.name}!` }}
{{ $json.email.toLowerCase() }}
{{ $json.text.split(",")[0] }}
{{ $json.name.trim() }}
Date/Time Formatting
{{ $now.format("YYYY-MM-DD") }}
{{ DateTime.fromISO($json.date).toFormat("dd/MM/yyyy") }}
{{ $now.plus({ days: 7 }).toISO() }}
{{ $now.minus({ hours: 2 }).toFormat("HH:mm") }}
Number Operations
{{ $json.price * 1.1 }}
{{ Math.round($json.value * 100) / 100 }}
{{ parseInt($json.count) }}
{{ parseFloat($json.amount) }}
Array Operations
{{ $json.items.length }}
{{ $json.users.map(u => u.name).join(", ") }}
{{ $json.items.filter(i => i.active) }}
{{ $json.products.find(p => p.id === "abc") }}
Common Mistakes
1. Missing .body for Webhooks
{{ $json.data }}
{{ $json.body.data }}
2. Wrong Node Reference Syntax
{{ $node[HTTP Request].json.data }}
{{ $node["HTTP Request"].json.data }}
3. Accessing Non-Existent Properties
{{ $json.user.name }}
{{ $json.user?.name ?? "N/A" }}
4. Expression vs Code Node
{{ $json.name }}
const items = $input.all();
return items.map(item => ({
json: { name: item.json.name.toUpperCase() }
}));
Special Variables
| Variable | Description |
|---|
$json | Current item's JSON data |
$binary | Current item's binary data |
$input | Input from previous node |
$node["Name"] | Access specific node's output |
$workflow | Workflow metadata |
$execution | Execution metadata |
$now | Current DateTime (Luxon) |
$today | Today at midnight (Luxon) |
$itemIndex | Current item's index |
$runIndex | Current run index (loops) |
$env | Environment variables |
$vars | n8n variables |
Luxon DateTime Reference
n8n uses Luxon for dates:
{{ $now.toFormat("yyyy-MM-dd HH:mm:ss") }}
{{ $now.toISO() }}
{{ $now.toLocaleString() }}
{{ DateTime.fromISO("2024-01-15") }}
{{ DateTime.fromFormat("15/01/2024", "dd/MM/yyyy") }}
{{ $now.plus({ days: 30 }) }}
{{ $now.startOf("month") }}
{{ $now.endOf("week") }}
{{ $now > DateTime.fromISO($json.dueDate) }}
{{ $now.diff(DateTime.fromISO($json.created), "days").days }}
Expression Debugging
- Use Set node to test expressions before complex nodes
- Check data structure with
{{ JSON.stringify($json) }}
- Use optional chaining
?. to prevent null errors
- Console isn't available - use Set node to inspect values
Based on n8n-skills by Romuald Członkowski • Adapted for Moltbot by fazer.ai
Source: fazer-ai/moltbot-skill-n8n — distributed by TomeVault.