Expressions
Expressions allow you to dynamically transform and reference data in n8n workflows. They enable you to access data from previous nodes, use built-in functions, and create complex data transformations.Expression Basics
Expressions in n8n are wrapped in double curly braces and start with an equals sign:When to Use Expressions
Expressions can be used in:- Node parameters (URLs, headers, body data)
- Conditional logic (IF nodes, Switch nodes)
- Data transformation (Set nodes, Code nodes)
- Filter operations
- Any string-type parameter
Expression Evaluation
TheExpression class handles all expression evaluation in n8n:
Expressions run in a sandboxed environment that blocks dangerous operations like
eval(), Function(), fetch(), and access to window or document objects.Data Access Patterns
Current Node Data
- JSON Data
- Binary Data
- Item Index
- Node Input
Access JSON data from the current item:
Previous Node Data
Multiple Items
When processing multiple items:Built-in Functions and Variables
Date and Time
Math Operations
String Operations
Array Operations
Object Operations
Workflow Data Proxy
TheWorkflowDataProxy class provides access to workflow execution data:
Workflow Metadata
Environment Variables
Expression Security
Sandbox Protection
The expression sandbox prevents malicious code execution:The safe
Object wrapper blocks dangerous methods like defineProperty, setPrototypeOf, and __defineGetter__ that could bypass security checks.Error Handling
Expressions can throw specific errors:Advanced Patterns
Conditional Expressions
Data Transformation
Dynamic Node References
Expressions can reference nodes dynamically:Expression Extensions
Custom extensions can be added to expressions:Expression Best Practices
- Keep expressions simple: Complex logic belongs in Code nodes
- Use descriptive variable names: When using intermediate variables
- Handle null/undefined: Always check for data existence
- Use type-safe operations: Be aware of data types
- Avoid side effects: Expressions should be pure functions
- Test with sample data: Use the expression editor’s test mode
- Document complex expressions: Add comments in Code nodes
Common Patterns
API Request with Dynamic Parameters
Data Validation
Error Messages
Next Steps
Error Handling
Handle errors and implement retry logic
Execution Modes
Understand workflow execution contexts