How to use Expressions in n8n | Built-In Functions in n8n

Learn How to use Expressions in n8n | Built-In Functions in n8n in this comprehensive n8n tutorial. Step-by-step guide with video, code examples, and expert tips from the n8n Zero to Hero course.

Table of Contents

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.
  • $json is 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.

Next Steps

Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.

Frequently Asked Questions

Expressions run inside individual node fields and are limited to a single line of JavaScript wrapped in `{{ }}`. The Code node is a dedicated node that accepts multi-line JavaScript or Python, making it the right tool for function definitions, loops, or logic that cannot fit on one line. The transcript shows an expression returning an invalid-syntax error when multi-line code is pasted in, even when collapsed to a single line.

`$json` references the output of the immediately previous node. You access fields with dot notation (`$json.customerName`) or bracket notation (`$json["email"]`). For nested objects and arrays, chain the path: `$json.order.products[0].name` returns the name of the first product in the array. To access a node that is not immediately previous, n8n lets you reference it by name using `$('Node Name')` and dot notation.

n8n's built-in string functions include `.extractDomain()`, `.extractEmail()`, `.extractUrl()`, and `.hash()`. For dates, `$now` returns the current datetime via the Luxon library, and you chain `.format('yyyy-MM-dd')` to reformat it or `.diff(DateTime.fromISO('2025-01-01'), 'days')` to calculate elapsed days. The full list is in n8n's official documentation under "Built-in functions and variables", organized by data type.

`$ifEmpty()` handles blank fields inline. The syntax is `$ifEmpty($json.email, 'Email not found')`: if the email field is empty, the expression returns the fallback string instead of null. The transcript demonstrates this by clearing the email field entirely and confirming the node outputs 'Email not found' rather than an error or a null value downstream.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources