Validate n8n expression syntax and fix common errors. Use when writing n8n expressions, using {{}} syntax, accessing $json/$node variables, troubleshooting expression errors, or working with webhook data in workflows.
Add this skill
npx mdskills install czlonkowski/n8n-expression-syntaxComprehensive n8n expression syntax guide with critical webhook gotchas and 15+ common mistakes
1---2name: n8n-expression-syntax3description: Validate n8n expression syntax and fix common errors. Use when writing n8n expressions, using {{}} syntax, accessing $json/$node variables, troubleshooting expression errors, or working with webhook data in workflows.4---56# n8n Expression Syntax78Expert guide for writing correct n8n expressions in workflows.910---1112## Expression Format1314All dynamic content in n8n uses **double curly braces**:1516```17{{expression}}18```1920**Examples**:21```22✅ {{$json.email}}23✅ {{$json.body.name}}24✅ {{$node["HTTP Request"].json.data}}25❌ $json.email (no braces - treated as literal text)26❌ {$json.email} (single braces - invalid)27```2829---3031## Core Variables3233### $json - Current Node Output3435Access data from the current node:3637```javascript38{{$json.fieldName}}39{{$json['field with spaces']}}40{{$json.nested.property}}41{{$json.items[0].name}}42```4344### $node - Reference Other Nodes4546Access data from any previous node:4748```javascript49{{$node["Node Name"].json.fieldName}}50{{$node["HTTP Request"].json.data}}51{{$node["Webhook"].json.body.email}}52```5354**Important**:55- Node names **must** be in quotes56- Node names are **case-sensitive**57- Must match exact node name from workflow5859### $now - Current Timestamp6061Access current date/time:6263```javascript64{{$now}}65{{$now.toFormat('yyyy-MM-dd')}}66{{$now.toFormat('HH:mm:ss')}}67{{$now.plus({days: 7})}}68```6970### $env - Environment Variables7172Access environment variables:7374```javascript75{{$env.API_KEY}}76{{$env.DATABASE_URL}}77```7879---8081## 🚨 CRITICAL: Webhook Data Structure8283**Most Common Mistake**: Webhook data is **NOT** at the root!8485### Webhook Node Output Structure8687```javascript88{89 "headers": {...},90 "params": {...},91 "query": {...},92 "body": { // ⚠️ USER DATA IS HERE!93 "name": "John",94 "email": "john@example.com",95 "message": "Hello"96 }97}98```99100### Correct Webhook Data Access101102```javascript103❌ WRONG: {{$json.name}}104❌ WRONG: {{$json.email}}105106✅ CORRECT: {{$json.body.name}}107✅ CORRECT: {{$json.body.email}}108✅ CORRECT: {{$json.body.message}}109```110111**Why**: Webhook node wraps incoming data under `.body` property to preserve headers, params, and query parameters.112113---114115## Common Patterns116117### Access Nested Fields118119```javascript120// Simple nesting121{{$json.user.email}}122123// Array access124{{$json.data[0].name}}125{{$json.items[0].id}}126127// Bracket notation for spaces128{{$json['field name']}}129{{$json['user data']['first name']}}130```131132### Reference Other Nodes133134```javascript135// Node without spaces136{{$node["Set"].json.value}}137138// Node with spaces (common!)139{{$node["HTTP Request"].json.data}}140{{$node["Respond to Webhook"].json.message}}141142// Webhook node143{{$node["Webhook"].json.body.email}}144```145146### Combine Variables147148```javascript149// Concatenation (automatic)150Hello {{$json.body.name}}!151152// In URLs153https://api.example.com/users/{{$json.body.user_id}}154155// In object properties156{157 "name": "={{$json.body.name}}",158 "email": "={{$json.body.email}}"159}160```161162---163164## When NOT to Use Expressions165166### ❌ Code Nodes167168Code nodes use **direct JavaScript access**, NOT expressions!169170```javascript171// ❌ WRONG in Code node172const email = '={{$json.email}}';173const name = '{{$json.body.name}}';174175// ✅ CORRECT in Code node176const email = $json.email;177const name = $json.body.name;178179// Or using Code node API180const email = $input.item.json.email;181const allItems = $input.all();182```183184### ❌ Webhook Paths185186```javascript187// ❌ WRONG188path: "{{$json.user_id}}/webhook"189190// ✅ CORRECT191path: "user-webhook" // Static paths only192```193194### ❌ Credential Fields195196```javascript197// ❌ WRONG198apiKey: "={{$env.API_KEY}}"199200// ✅ CORRECT201Use n8n credential system, not expressions202```203204---205206## Validation Rules207208### 1. Always Use {{}}209210Expressions **must** be wrapped in double curly braces.211212```javascript213❌ $json.field214✅ {{$json.field}}215```216217### 2. Use Quotes for Spaces218219Field or node names with spaces require **bracket notation**:220221```javascript222❌ {{$json.field name}}223✅ {{$json['field name']}}224225❌ {{$node.HTTP Request.json}}226✅ {{$node["HTTP Request"].json}}227```228229### 3. Match Exact Node Names230231Node references are **case-sensitive**:232233```javascript234❌ {{$node["http request"].json}} // lowercase235❌ {{$node["Http Request"].json}} // wrong case236✅ {{$node["HTTP Request"].json}} // exact match237```238239### 4. No Nested {{}}240241Don't double-wrap expressions:242243```javascript244❌ {{{$json.field}}}245✅ {{$json.field}}246```247248---249250## Common Mistakes251252For complete error catalog with fixes, see [COMMON_MISTAKES.md](COMMON_MISTAKES.md)253254### Quick Fixes255256| Mistake | Fix |257|---------|-----|258| `$json.field` | `{{$json.field}}` |259| `{{$json.field name}}` | `{{$json['field name']}}` |260| `{{$node.HTTP Request}}` | `{{$node["HTTP Request"]}}` |261| `{{{$json.field}}}` | `{{$json.field}}` |262| `{{$json.name}}` (webhook) | `{{$json.body.name}}` |263| `'={{$json.email}}'` (Code node) | `$json.email` |264265---266267## Working Examples268269For real workflow examples, see [EXAMPLES.md](EXAMPLES.md)270271### Example 1: Webhook to Slack272273**Webhook receives**:274```json275{276 "body": {277 "name": "John Doe",278 "email": "john@example.com",279 "message": "Hello!"280 }281}282```283284**In Slack node text field**:285```286New form submission!287288Name: {{$json.body.name}}289Email: {{$json.body.email}}290Message: {{$json.body.message}}291```292293### Example 2: HTTP Request to Email294295**HTTP Request returns**:296```json297{298 "data": {299 "items": [300 {"name": "Product 1", "price": 29.99}301 ]302 }303}304```305306**In Email node** (reference HTTP Request):307```308Product: {{$node["HTTP Request"].json.data.items[0].name}}309Price: ${{$node["HTTP Request"].json.data.items[0].price}}310```311312### Example 3: Format Timestamp313314```javascript315// Current date316{{$now.toFormat('yyyy-MM-dd')}}317// Result: 2025-10-20318319// Time320{{$now.toFormat('HH:mm:ss')}}321// Result: 14:30:45322323// Full datetime324{{$now.toFormat('yyyy-MM-dd HH:mm')}}325// Result: 2025-10-20 14:30326```327328---329330## Data Type Handling331332### Arrays333334```javascript335// First item336{{$json.users[0].email}}337338// Array length339{{$json.users.length}}340341// Last item342{{$json.users[$json.users.length - 1].name}}343```344345### Objects346347```javascript348// Dot notation (no spaces)349{{$json.user.email}}350351// Bracket notation (with spaces or dynamic)352{{$json['user data'].email}}353```354355### Strings356357```javascript358// Concatenation (automatic)359Hello {{$json.name}}!360361// String methods362{{$json.email.toLowerCase()}}363{{$json.name.toUpperCase()}}364```365366### Numbers367368```javascript369// Direct use370{{$json.price}}371372// Math operations373{{$json.price * 1.1}} // Add 10%374{{$json.quantity + 5}}375```376377---378379## Advanced Patterns380381### Conditional Content382383```javascript384// Ternary operator385{{$json.status === 'active' ? 'Active User' : 'Inactive User'}}386387// Default values388{{$json.email || 'no-email@example.com'}}389```390391### Date Manipulation392393```javascript394// Add days395{{$now.plus({days: 7}).toFormat('yyyy-MM-dd')}}396397// Subtract hours398{{$now.minus({hours: 24}).toISO()}}399400// Set specific date401{{DateTime.fromISO('2025-12-25').toFormat('MMMM dd, yyyy')}}402```403404### String Manipulation405406```javascript407// Substring408{{$json.email.substring(0, 5)}}409410// Replace411{{$json.message.replace('old', 'new')}}412413// Split and join414{{$json.tags.split(',').join(', ')}}415```416417---418419## Debugging Expressions420421### Test in Expression Editor4224231. Click field with expression4242. Open expression editor (click "fx" icon)4253. See live preview of result4264. Check for errors highlighted in red427428### Common Error Messages429430**"Cannot read property 'X' of undefined"**431→ Parent object doesn't exist432→ Check your data path433434**"X is not a function"**435→ Trying to call method on non-function436→ Check variable type437438**Expression shows as literal text**439→ Missing {{ }}440→ Add curly braces441442---443444## Expression Helpers445446### Available Methods447448**String**:449- `.toLowerCase()`, `.toUpperCase()`450- `.trim()`, `.replace()`, `.substring()`451- `.split()`, `.includes()`452453**Array**:454- `.length`, `.map()`, `.filter()`455- `.find()`, `.join()`, `.slice()`456457**DateTime** (Luxon):458- `.toFormat()`, `.toISO()`, `.toLocal()`459- `.plus()`, `.minus()`, `.set()`460461**Number**:462- `.toFixed()`, `.toString()`463- Math operations: `+`, `-`, `*`, `/`, `%`464465---466467## Best Practices468469### ✅ Do470471- Always use {{ }} for dynamic content472- Use bracket notation for field names with spaces473- Reference webhook data from `.body`474- Use $node for data from other nodes475- Test expressions in expression editor476477### ❌ Don't478479- Don't use expressions in Code nodes480- Don't forget quotes around node names with spaces481- Don't double-wrap with extra {{ }}482- Don't assume webhook data is at root (it's under .body!)483- Don't use expressions in webhook paths or credentials484485---486487## Related Skills488489- **n8n MCP Tools Expert**: Learn how to validate expressions using MCP tools490- **n8n Workflow Patterns**: See expressions in real workflow examples491- **n8n Node Configuration**: Understand when expressions are needed492493---494495## Summary496497**Essential Rules**:4981. Wrap expressions in {{ }}4992. Webhook data is under `.body`5003. No {{ }} in Code nodes5014. Quote node names with spaces5025. Node names are case-sensitive503504**Most Common Mistakes**:505- Missing {{ }} → Add braces506- `{{$json.name}}` in webhooks → Use `{{$json.body.name}}`507- `{{$json.email}}` in Code → Use `$json.email`508- `{{$node.HTTP Request}}` → Use `{{$node["HTTP Request"]}}`509510For more details, see:511- [COMMON_MISTAKES.md](COMMON_MISTAKES.md) - Complete error catalog512- [EXAMPLES.md](EXAMPLES.md) - Real workflow examples513514---515516**Need Help?** Reference the n8n expression documentation or use n8n-mcp validation tools to check your expressions.517
Full transparency — inspect the skill content before installing.