Skip to main content

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

The Expression 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

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

The WorkflowDataProxy 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

  1. Keep expressions simple: Complex logic belongs in Code nodes
  2. Use descriptive variable names: When using intermediate variables
  3. Handle null/undefined: Always check for data existence
  4. Use type-safe operations: Be aware of data types
  5. Avoid side effects: Expressions should be pure functions
  6. Test with sample data: Use the expression editor’s test mode
  7. Document complex expressions: Add comments in Code nodes
Expression Editor Tips:
  • Press Ctrl+Space for autocomplete
  • Hover over variables to see their values
  • Use the “Test with sample data” feature
  • Check the expression syntax highlighting for errors

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