$npx -y skills add czlonkowski/n8n-skills --skill n8n-expression-syntaxValidate n8n expression syntax and fix common errors. Use when writing n8n expressions, using {{}} syntax, accessing $json/$node variables, troubleshooting expression errors, mapping data between nodes, or referencing webhook data in workflows. Use this skill whenever configuring
| 1 | # n8n Expression Syntax |
| 2 | |
| 3 | Expert guide for writing correct n8n expressions in workflows. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## Expression Format |
| 8 | |
| 9 | All dynamic content in n8n uses **double curly braces**: |
| 10 | |
| 11 | ``` |
| 12 | {{expression}} |
| 13 | ``` |
| 14 | |
| 15 | **Examples**: |
| 16 | ``` |
| 17 | ✅ {{$json.email}} |
| 18 | ✅ {{$json.body.name}} |
| 19 | ✅ {{$node["HTTP Request"].json.data}} |
| 20 | ❌ $json.email (no braces - treated as literal text) |
| 21 | ❌ {$json.email} (single braces - invalid) |
| 22 | ``` |
| 23 | |
| 24 | --- |
| 25 | |
| 26 | ## Core Variables |
| 27 | |
| 28 | ### $json - Current Node Output |
| 29 | |
| 30 | Access data from the current node: |
| 31 | |
| 32 | ```javascript |
| 33 | {{$json.fieldName}} |
| 34 | {{$json['field with spaces']}} |
| 35 | {{$json.nested.property}} |
| 36 | {{$json.items[0].name}} |
| 37 | ``` |
| 38 | |
| 39 | ### $node - Reference Other Nodes |
| 40 | |
| 41 | Access data from any previous node: |
| 42 | |
| 43 | ```javascript |
| 44 | {{$node["Node Name"].json.fieldName}} |
| 45 | {{$node["HTTP Request"].json.data}} |
| 46 | {{$node["Webhook"].json.body.email}} |
| 47 | ``` |
| 48 | |
| 49 | **Important**: |
| 50 | - Node names **must** be in quotes |
| 51 | - Node names are **case-sensitive** |
| 52 | - Must match exact node name from workflow |
| 53 | |
| 54 | ### $now - Current Timestamp |
| 55 | |
| 56 | Access current date/time: |
| 57 | |
| 58 | ```javascript |
| 59 | {{$now}} |
| 60 | {{$now.toFormat('yyyy-MM-dd')}} |
| 61 | {{$now.toFormat('HH:mm:ss')}} |
| 62 | {{$now.plus({days: 7})}} |
| 63 | ``` |
| 64 | |
| 65 | ### $env - Environment Variables |
| 66 | |
| 67 | Access environment variables: |
| 68 | |
| 69 | ```javascript |
| 70 | {{$env.API_KEY}} |
| 71 | {{$env.DATABASE_URL}} |
| 72 | ``` |
| 73 | |
| 74 | **Warning**: Some n8n instances have `N8N_BLOCK_ENV_ACCESS_IN_NODE` enabled, which blocks `$env` access entirely. If `$env` returns errors, use alternative approaches: |
| 75 | - Store values in credentials instead |
| 76 | - Use a Set node with manually entered values |
| 77 | - Pass values through webhook query parameters |
| 78 | |
| 79 | --- |
| 80 | |
| 81 | ## 🚨 CRITICAL: Webhook Data Structure |
| 82 | |
| 83 | **Most Common Mistake**: Webhook data is **NOT** at the root! |
| 84 | |
| 85 | ### Webhook Node Output Structure |
| 86 | |
| 87 | ```javascript |
| 88 | { |
| 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 | ``` |
| 99 | |
| 100 | ### Correct Webhook Data Access |
| 101 | |
| 102 | ```javascript |
| 103 | ❌ WRONG: {{$json.name}} |
| 104 | ❌ WRONG: {{$json.email}} |
| 105 | |
| 106 | ✅ CORRECT: {{$json.body.name}} |
| 107 | ✅ CORRECT: {{$json.body.email}} |
| 108 | ✅ CORRECT: {{$json.body.message}} |
| 109 | ``` |
| 110 | |
| 111 | **Why**: Webhook node wraps incoming data under `.body` property to preserve headers, params, and query parameters. |
| 112 | |
| 113 | --- |
| 114 | |
| 115 | ## Common Patterns |
| 116 | |
| 117 | ### Access Nested Fields |
| 118 | |
| 119 | ```javascript |
| 120 | // Simple nesting |
| 121 | {{$json.user.email}} |
| 122 | |
| 123 | // Array access |
| 124 | {{$json.data[0].name}} |
| 125 | {{$json.items[0].id}} |
| 126 | |
| 127 | // Bracket notation for spaces |
| 128 | {{$json['field name']}} |
| 129 | {{$json['user data']['first name']}} |
| 130 | ``` |
| 131 | |
| 132 | ### Reference Other Nodes |
| 133 | |
| 134 | ```javascript |
| 135 | // Node without spaces |
| 136 | {{$node["Set"].json.value}} |
| 137 | |
| 138 | // Node with spaces (common!) |
| 139 | {{$node["HTTP Request"].json.data}} |
| 140 | {{$node["Respond to Webhook"].json.message}} |
| 141 | |
| 142 | // Webhook node |
| 143 | {{$node["Webhook"].json.body.email}} |
| 144 | ``` |
| 145 | |
| 146 | ### Combine Variables |
| 147 | |
| 148 | ```javascript |
| 149 | // Concatenation (automatic) |
| 150 | Hello {{$json.body.name}}! |
| 151 | |
| 152 | // In URLs |
| 153 | https://api.example.com/users/{{$json.body.user_id}} |
| 154 | |
| 155 | // In object properties |
| 156 | { |
| 157 | "name": "={{$json.body.name}}", |
| 158 | "email": "={{$json.body.email}}" |
| 159 | } |
| 160 | ``` |
| 161 | |
| 162 | --- |
| 163 | |
| 164 | ## When NOT to Use Expressions |
| 165 | |
| 166 | ### ❌ Code Nodes |
| 167 | |
| 168 | Code nodes use **direct JavaScript access**, NOT expressions! |
| 169 | |
| 170 | ```javascript |
| 171 | // ❌ WRONG in Code node |
| 172 | const email = '={{$json.email}}'; |
| 173 | const name = '{{$json.body.name}}'; |
| 174 | |
| 175 | // ✅ CORRECT in Code node |
| 176 | const email = $json.email; |
| 177 | const name = $json.body.name; |
| 178 | |
| 179 | // Or using Code node API |
| 180 | const email = $input.item.json.email; |
| 181 | const allItems = $input.all(); |
| 182 | ``` |
| 183 | |
| 184 | ### ❌ Webhook Paths |
| 185 | |
| 186 | ```javascript |
| 187 | // ❌ WRONG |
| 188 | path: "{{$json.user_id}}/webhook" |
| 189 | |
| 190 | // ✅ CORRECT |
| 191 | path: "user-webhook" // Static paths only |
| 192 | ``` |
| 193 | |
| 194 | ### ❌ Credential Fields |
| 195 | |
| 196 | ```javascript |
| 197 | // ❌ WRONG |
| 198 | apiKey: "={{$env.API_KEY}}" |
| 199 | |
| 200 | // ✅ CORRECT |
| 201 | Use n8n credential system, not expressions |
| 202 | ``` |
| 203 | |
| 204 | --- |
| 205 | |
| 206 | ## The transform gatekeeper |
| 207 | |
| 208 | Before you add any node — or write any code — to transform data, walk this order and stop at the first that fits: |
| 209 | |
| 210 | 1. **Expression** (`{{ ... }}`) in the consuming field. Property access, method chains (`.map().filter().join()`), ternaries, string building, Luxon date math — if it's "take A, produce B" without intermediate variables, it's an expression. This covers most "just transform this" cases. |
| 211 | 2. **Arrow-function IIFE inside an Edit Fields field.** When the logic needs intermediate variables, branching, or comments but still operates on one item, wrap it in an immediately-invoked arrow function right in the field value: |
| 212 | |
| 213 | ``` |
| 214 | ={{ (() => { |
| 215 | const items = $json.line_items; |
| 216 | co |