Expressions Overview¶
Expressions allow dynamic values in node parameters using data from previous nodes.
Syntax¶
Expressions use double curly braces:
Basic Examples¶
Access JSON Data¶
String Interpolation¶
Mathematical Operations¶
Expression Context¶
Every expression has access to:
| Variable | Description |
|---|---|
$json |
Current item's JSON data |
$item |
Current item index (0-based) |
$node |
Access other nodes' output |
$input |
Input data helpers |
$env |
Environment variables |
$now |
Current timestamp |
Where to Use Expressions¶
Expressions work in most node parameter fields:
{
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"url": "https://api.example.com/users/{{ $json.userId }}",
"method": "GET"
}
}
Expression Types¶
Simple Reference¶
Direct field access:
Nested Access¶
Access nested objects:
Array Access¶
Access array elements:
Conditional¶
Ternary expressions:
Function Calls¶
Use built-in functions:
Data Flow Example¶
Node A outputs: { "user": "John", "score": 85 }
↓
Node B receives and uses: {{ $json.user }} scored {{ $json.score }}
↓
Result: "John scored 85"
Error Handling¶
Undefined Values¶
Use optional chaining:
Default Values¶
Provide fallbacks:
Debugging Expressions¶
Code Node¶
Test expressions in a Code node:
Log Output¶
Log values for debugging:
Best Practices¶
- Use meaningful field names - Makes expressions readable
- Handle missing data - Use defaults and null checks
- Keep expressions simple - Complex logic belongs in Code nodes
- Test with sample data - Verify before production
Next Steps¶
- Variables Reference - All available variables
- Functions Reference - Built-in functions