Overview
This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 3. Deep Dive Concepts.
Watch the video above for the full tutorial, or read the written guide below.
What are Expressions in n8n, and when do you use them?
Expressions in n8n let you transform data inside any node field using single-line JavaScript, without building a separate code block. You activate them by switching a field from Fixed to Expression mode and wrapping your code in double curly braces {{ }}. Expressions support raw JavaScript, JMESPath for querying JSON, and the Luxon datetime library, plus n8n's own built-in data-transformation functions.
How do you access and transform data with n8n Expressions?
The $json variable gives you access to the output of the immediately previous node. You can read any field with dot notation ($json.customerName) or bracket notation ($json["email"]). For nested objects and arrays, chain the path: $json.order.products[0].name drills into the first item of an array. Both approaches use JMESPath querying under the hood, so pick whichever style is more readable for a given situation. To pull data from a node that is not immediately previous, reference it by name using $('Node Name') and dot notation.
Built-in functions extend what raw JavaScript alone can do. Typing a dot after a string value surfaces methods like .extractDomain(), which pulls the domain from an email address without any manual split logic. The $ifEmpty($json.email, 'Email not found') function returns a fallback string when a field is blank, making data cleanup a one-liner. For dates, $now returns the current timestamp via the Luxon library, and chaining .format('yyyy-MM-dd') reformats it, while .diff(DateTime.fromISO('2025-01-01'), 'days') calculates elapsed days. n8n's documentation page for "Built-in functions and variables" lists all available methods by category: arrays, booleans, numbers, objects, and strings.
Expressions are single-line only. The transcript demonstrates this directly: pasting a multi-line JavaScript function inside {{ }} produces an invalid-syntax error, even when collapsed onto one line. Any logic requiring function definitions, loops, or multiple statements belongs in the Code node, covered in the next lesson.
Key Takeaways
- Expressions activate inside
{{ }}on any node field switched to Expression mode; everything inside runs as single-line JavaScript. $jsonis the primary data accessor: dot notation ($json.email) and bracket notation ($json["email"]) both work, and you can chain them to reach nested objects and array indexes.- Built-in functions like
.extractDomain(),$ifEmpty(), and Luxon date methods ($now.format(),$now.diff()) handle common transforms without custom code, and n8n's official docs list every available function by data type. - Expressions are single-line only. Multi-line logic, function definitions, and loops require the Code node, which supports both JavaScript and Python.
- Check built-in functions before writing custom code. The n8n documentation flags whether each function is available in expressions, in the Code node, or in both, so you can pick the right tool before writing anything.
Related Lessons
- Lesson 11: How Branching works in n8n Workflows | Smart Automations with Multiple Paths
- Lesson 12: How to Use Merge Node in n8n | Combine Data Like a Pro
- Lesson 13: How to Use Set Node in n8n | Edit Fields Node | Add, Edit, Clean Data
- Lesson 14: How to Use Aggregate Node in n8n | Combine & Summarize Data
- Lesson 15: How to Use Remove Duplicates Node in n8n | Clean Your Data Fast
Next Steps
Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.