Basic Expressions Intro

Difficulty
2/10
Tags
EssentialsManual TriggerEdit Fields (Set)ExpressionsJSON

So far, you've used static values like "Hello, n8n!" in your nodes. But real workflows need dynamic values that change based on the data.

Expressions let you reference data from previous nodes and transform it. They're wrapped in double curly braces: {{ }}.

In this lesson, you'll learn to combine fields from your data using expressions.

What you'll practice:

  • Using the $json object to access current item data
  • Combining multiple fields with string concatenation
  • Writing your first expressions

Your Task

  1. 1Copy the exercise below
  2. 2Paste into your n8n editor (Ctrl+V)
  3. 3Solve it — use hints if you get stuck
  4. 4Check the solution when done

The exercise workflow has user data with first_name and last_name fields. Add an Edit Fields node that creates a full_name field by combining them.

Input data:

{
  "first_name": "Jane",
  "last_name": "Doe"
}

Expected output:

{
  "full_name": "Jane Doe"
}

Use an expression to combine the two fields with a space between them.

Get the exercise workflow

Create a free account to copy exercises into your n8n editor.

Hints

  1. Add an Edit Fields node after the existing nodes
  2. Add a new field called full_name
  3. Click the field type selector (the icon on the right of the value field) and select "Expression"
  4. Enter the expression: {{ $json.first_name + " " + $json.last_name }}
  5. Run the workflow and verify the output shows "Jane Doe"

Alternative syntax:

You can also use template literals: {{ $json.first_name }} {{ $json.last_name }}

Both approaches produce the same result.

Explanation

How expressions work:

Everything inside {{ }} is JavaScript. You have access to special variables like $json which contains the current item's data.

  • $json.first_name gets the value "Jane" from the input
  • $json.last_name gets the value "Doe" from the input
  • + concatenates strings together
  • " " is a literal space character

Two ways to combine strings:

  1. Concatenation: {{ $json.first_name + " " + $json.last_name }}
  2. Template syntax: {{ $json.first_name }} {{ $json.last_name }}

The template syntax is often cleaner when you're mixing static text with dynamic values. The concatenation approach gives you more control and is better for complex logic.

Expression context:

$json always refers to the current item being processed. When you have multiple items flowing through your workflow, the expression runs once for each item.

Copy the Solution

Paste into n8n with Ctrl+V to compare with your approach.

How was this lesson?

Get the solution workflow

Create a free account to copy solutions into your n8n editor.

Related Content

Continue your learning journey with these related lessons and guides: