Learn › n8n Foundations: From Zero to First Automation › Working with Data: Expressions and $json

Working with Data: Expressions and $json

Beginner 🕐 13 min Lesson 7 of 15
What you'll learn
  • Write n8n expressions using {{ }} syntax to reference dynamic values from previous nodes
  • Use $json to access current item fields and $('Node Name') to reference earlier nodes
  • Apply built-in variables like $now, $today, and $itemIndex in workflow parameters

Expressions Are n8n's Dynamic Values

In n8n, most node parameters accept either a fixed value (you type it in) or an expression — a small piece of code wrapped in double curly braces: {{ }}. Expressions let you pull in data from previous nodes, do light calculations, and format values dynamically at runtime.

To switch a field from a fixed value to an expression, click the field and look for the expression toggle (a small lightning bolt icon on the right). Once in expression mode, everything between {{ and }} is evaluated as JavaScript.

The $json Variable

$json is the most important variable in n8n expressions. It refers to the JSON data of the current item being processed. If a Google Sheets node returned a row with columns "Name", "Email", and "Company", you access those values as:

{{ $json.Name }}
{{ $json.Email }}
{{ $json.Company }}

You can navigate nested objects with dot notation: {{ $json.address.city }}. For array values, use bracket notation: {{ $json.tags[0] }}.

Referencing Other Nodes

By default, $json refers to the current item from the immediately preceding node. To reference data from a different node earlier in the workflow, use $('Node Name'):

{{ $('Google Sheets').item.json.Email }}

Replace "Google Sheets" with the exact name of the node you want to pull from. This is how you use data from a node that is not your direct predecessor — for example, referencing the original webhook payload after several transformation steps.

Built-in Variables

n8n provides several built-in variables available in every expression:

  • $now — the current date and time as a Luxon DateTime object: {{ $now.toISO() }}
  • $today — today's date at midnight: {{ $today.toFormat('yyyy-MM-dd') }}
  • $workflow.id — the current workflow's ID
  • $execution.id — the unique ID of the current execution run
  • $itemIndex — the zero-based index of the current item in the list

Common Expression Patterns

Here are expressions you will use constantly:

  • Concatenate strings: {{ $json.FirstName + ' ' + $json.LastName }}
  • Format a date: {{ $now.toFormat('MMMM d, yyyy') }}
  • Fallback value: {{ $json.nickname || $json.name }}
  • Convert to lowercase: {{ $json.email.toLowerCase() }}
  • Check a condition: {{ $json.status === 'active' ? 'Yes' : 'No' }}

The expression editor in n8n shows you a live preview of the result as you type — use it to verify your expression before running the workflow.

Key takeaways
  • Expressions use {{ }} syntax and are evaluated as JavaScript — toggle a field to expression mode using the lightning bolt icon
  • $json refers to the current item's data; use dot notation ($json.field) and bracket notation ($json.array[0]) to access values
  • Built-in variables like $now (current time as Luxon DateTime) and $itemIndex are always available in any expression