/n8n-tutorials

How to use expressions in n8n?

Learn how to use expressions in n8n to automate workflows, transform data, and boost efficiency with clear examples and practical tips.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to use expressions in n8n?

In n8n, you use expressions by typing {{ ... }} inside any field that shows the “gear” icon or the “Expression” toggle. An expression lets you pull values from previous nodes (like {{$json.email}}), combine them, or run small pieces of JavaScript. Expressions always run at execution time, not when you type them, and they read whatever data the previous node outputs. In practice, you use expressions whenever a value shouldn’t be hard‑coded — things like dynamic emails, IDs, URLs, or timestamps.

 

What an Expression Actually Is

 

An n8n expression is just a short piece of JavaScript wrapped in {{ }} that lives inside a field. When the workflow runs, n8n evaluates that JavaScript against the current item’s data. “Item” means the JSON object flowing from node to node.

Inside an expression, you can use:

  • $json — the current item’s JSON (most common)
  • $prevNode — access data from a specific previous node
  • $node — info about a node’s execution
  • $env — environment variables
  • JavaScript functions — like Date(), String(), string methods, etc.

 

The Core Pattern You’ll Use 90% of the Time

 

The most common expression is pulling something from a previous node, usually the node right before:

{{$json.email}}

This means: “in this item, look inside the JSON, and return the value called email.”

If that field was nested, you just go deeper:

{{$json.user.profile.lastName}}

If you need the output of a specific node:

{{$prevNode["Get User"].json.id}}

 

Enable Expression Mode

 

You can type {{ }} in the field, or click the small “Expression” toggle. When enabled, the field becomes dynamic and n8n highlights it in purple.

Tip: If the expression is invalid, n8n will highlight an error right in the field. It won’t break your whole workflow — it just won’t evaluate during execution.

 

Real Production Examples

 

Building a dynamic name (after an API returns first and last name):

{{$json.firstName + " " + $json.lastName}}

Compose a dynamic Slack message:

{{"New user signed up: " + $json.email + " at " + new Date().toISOString()}}

Read an environment variable (great for API URLs or secrets):

{{$env.BASE_URL + "/api/v2/users"}}

Create a fallback when a field might be missing:

{{$json.username || "unknown-user"}}

 

How Expressions Flow Through Nodes

 

Every node runs per item. That means:

  • If a previous node returns 5 items, your expression runs 5 times.
  • $json always refers to the item currently being processed.
  • Expressions do not modify the data; they only read from it.

So if you want to transform data, you usually use a Code node or Set node, not just an expression field.

 

Common Pitfalls (Real-World Advice)

 

  • Forgetting the field is per-item — leads to unexpected values if your workflow has multiple items.
  • Trying to run long or complex logic in an expression — for anything big, use a Code node instead.
  • Using expressions in credentials — n8n does not support that (for security reasons).
  • Expecting expressions to run at design time — they only run during execution.

One good test is to switch the field to expression mode and click the “value preview” icon (the little eye). n8n shows the actual value based on the last workflow run.

 

When to Choose Expression vs Code Node

 

Use an expression when the logic is short and tied to a specific field. Use a Code node when the logic grows beyond a few lines or you need loops, conditionals, or multi-field transformations. Expression fields should remain readable — that’s the real production rule.

 

Reliable Pattern for Long-Term Workflows

 

In production, expressions are best for:

  • Dynamic URLs
  • Lookup of IDs from previous nodes
  • Timestamp generation
  • Building messages or payloads
  • Extracting nested fields

Anything heavy or anything that changes often should live in a Code node or a database, not inside long expressions. That keeps your workflow maintainable and error‑resistant.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022