Hello! Welcome to your next lesson in our journey through n8n's core concepts.
In our last session, we drew a clear line between developing a workflow (in an inactive state) and deploying it (in an active state). You learned that activating a workflow is what makes its triggers "live" and ready to run automatically.
Now that we know how to turn our workflows on, we need to master the art of working with the data that flows through them. A workflow isn't very useful if its nodes can't talk to each other. This lesson focuses on the single most important tool for that communication: the Expression Editor. By the end of this lesson, you will be able to use the Expression Editor to dynamically access and display data passed from previous nodes, making your workflows responsive and powerful.
1. From Static to Dynamic: The Role of Expressions
In n8n, each node in a sequence receives the output from the node that came before it. As a software developer, you can think of this as a pipeline where one function's return value becomes the input for the next function. This data is structured as an array of JSON objects.
Let's say a Webhook Trigger receives the following data:
{
"body": {
"customer_name": "Alex Smith",
"order_id": "xyz-123",
"amount": 99.99
}
}
If the next node is a "Send Email" node, how do we tell it to use "Alex Smith" in the subject line? We can't just type "Alex Smith," because the next order will have a different customer name. We need a way to create a dynamic reference to that piece of data.
This is precisely what Expressions are for.
The n8n documentation provides a concise introduction to Expressions. Please read the first few paragraphs to get a formal definition of what they are and their purpose.
Read the introductory section and the 'Writing expressions' section. Focus on understanding that expressions allow parameters to be set dynamically and are enclosed in {{ }}.
As the documentation states, expressions are small snippets of code enclosed in double curly braces, like {{ your_code_here }}, that allow you to dynamically set node parameters.
2. The Expression Editor Interface
When you click on a field that supports expressions, n8n opens the Expression Editor. This is your primary interface for building these dynamic references.
It has three main parts:
- Variable Selector (Left): A tree view of all the data available from previous nodes. This is incredibly useful for exploring the data structure.
- Expression Field (Top Right): Where you write your expression.
- Result Preview (Bottom Right): Shows you the live result of your expression based on the data from the last execution. This immediate feedback is vital for debugging.

3. Accessing Data with $json
The most common task you'll perform in the Expression Editor is accessing data from the node that came just before the current one. The primary way to do this is with the special $json variable.
$json is a shortcut that refers to the json object of the incoming item. You can then use standard dot notation to access its properties.
{{ $json.propertyName }}{{ $json.nestedObject.propertyName }}
Let's see this in a real-world scenario. The following video demonstrates building a simple weather report workflow. The key part for us is how it uses an expression to dynamically populate the subject line of an email.
n8n tutorial for developers - Every Dev Should Know This
This video from ByteGrad builds a practical weather workflow. Watch how the creator uses the Expression Editor to make the email subject line dynamic.
Watch the segment from 07:49 to 09:20. Pay close attention to how the 'name' property from the weather node's JSON output is used in the Gmail node's 'Subject' field. Notice how dragging the variable from the left panel automatically creates the correct expression.
As you saw, the expression Weather report for {{ $json.name }} dynamically inserts the city name returned by the previous "OpenWeatherMap" node. If the input city changes, the email subject automatically updates.
This pattern of replacing a hardcoded value with a dynamic expression is fundamental to n8n.
Test your understanding!
A previous node provides the following JSON output:
{
"user": {
"id": 734,
"contact_info": {
"email": "dev@n8n.io",
"phone": "555-0123"
}
},
"last_login": "2023-10-27T10:00:00Z"
}
What expression would you write to retrieve the user's email address?
Show answer
The correct expression is: {{ $json.user.contact_info.email }}
4. Basic Data Manipulation within Expressions
The power of expressions goes beyond simply displaying data. Because expressions are executed as JavaScript, you can use standard JavaScript methods to perform simple transformations directly within the {{ }}.
This is a powerful feature that will feel natural given your background. Let's watch an example where a full name is split to extract just the first name.
Master JSON & Data Transformation in 19 Minutes (Most Valuable n8n Skill)
This clip from Michele Torti's tutorial on JSON and data transformation is a perfect demonstration of using a JavaScript method inside an expression.
Watch from 08:01 to 12:18. The video first shows how to reference a 'full_name' field using {{ $json.full_name }}. Then, focus on how it's extended with JavaScript: {{ $json.full_name.split(' ').first() }} to isolate the first name. (Note: .first() is a convenient n8n helper method; in standard JS you might use [0].)
This demonstrates a key concept: an expression is not just a placeholder; it's an executable piece of code. You can use any valid JavaScript that returns a value. This includes string manipulation (.split(), .toUpperCase(), .slice()), mathematical operations, and more.
5. Advanced Concepts: A Look Ahead
While $json is your most common tool, it's good to be aware of the full power available to you, especially as you aim for comprehensive mastery.
Accessing Data from Any Previous Node
A common question is: "What if the data I need isn't from the node right before this one?" A crucial concept in n8n is that a node has access to the data from all preceding nodes in its execution path.
n8n tutorial for developers - Every Dev Should Know This
This short clip from the 'n8n for developers' tutorial makes this important point very clearly.
Watch from 19:15 to 19:52. Notice how the AI Agent node has access to data from both the weather service node and the even earlier form submission trigger node.
In later lessons, we'll cover the specific syntax ($("Node Name").item.json.property) used to pinpoint data from a specific node by its name. For now, just remember that the data is available.
Writing Multi-line JavaScript
For more complex logic, you can write multi-line JavaScript using an Immediately Invoked Function Expression (IIFE) syntax.
Example from the docs:
{{
(()=>{
let end = DateTime.fromISO('2017-03-13');
let start = DateTime.fromISO('2017-02-13');
let diffInMonths = end.diff(start, 'months');
return diffInMonths.toObject();
})()
}}
This shows that you are not limited to one-liners. You can declare variables and perform several steps before returning a final value, all within a single expression field. We will revisit this when we encounter more complex transformation needs.
Conclusion
You have now learned the fundamentals of making your workflows dynamic. The Expression Editor is the bridge that connects your nodes, allowing them to share and act upon data.
Key Takeaways:
- Purpose: Expressions, written inside
{{ }}, allow you to use data from previous nodes to dynamically configure the parameters of subsequent nodes. - The
$jsonVariable: This is your primary tool for accessing the JSON data from the immediately preceding node (e.g.,{{ $json.propertyName }}). - JavaScript is Built-in: You can use standard JavaScript methods (like
.split()or.toUpperCase()) within expressions to perform on-the-fly data manipulation. - Live Feedback: The Expression Editor's result preview is essential for writing and validating your expressions correctly.
So far, we've used expressions to access data and perform very simple manipulations. But what if you need to restructure data more significantly—like renaming fields, adding new ones based on calculations, or changing data types?
In our next lesson, we will explore the Set node, a dedicated tool designed for exactly these kinds of basic data transformations, which you'll use in conjunction with the expression skills you learned today.