Contents

n8n Expressions Tutorial: $json, $('Node'), Dates, and Common Functions

Expressions let node parameters change dynamically based on data. You can switch any parameter field to Expression mode (using the Fixed / Expression toggle next to the field, or by typing {{).

Inside {{ }}, you write JavaScript, so you can use JavaScript syntax and methods.

Read the current item: $json

{{ $json.name }}
{{ $json.address.city }}
{{ $json.tags[0] }}
{{ $json["field name"] }}

When a field name has spaces or special characters, use brackets [...].

The easiest way is to drag a field from the INPUT panel on the left into a parameter. n8n will generate the correct expression automatically.

Edit Fields node uses an expression to generate a message
Edit Fields: drag an INPUT field on the left into the expression, and the composed message appears immediately in OUTPUT on the right

Read data from another node: $('Node Name')

$json can only read the output of the previous node. To read from an earlier node:

{{ $('Google Sheets').item.json.email }}
SyntaxMeaning
$('Node').itemThe item corresponding to the current item (most common)
$('Node').first()The first item output by that node
$('Node').last()The last item
$('Node').all()All items (array)
{{ $('Webhook').item.json.body.customer_id }}
{{ $('Get settings').first().json.api_url }}
{{ $('Orders').all().length }} orders

If you rename a node, n8n automatically updates its name in expressions.

String handling

{{ $json.name.trim() }}
{{ $json.email.toLowerCase() }}
{{ $json.title.slice(0, 50) }}…
{{ $json.text.replaceAll('\n', ' ') }}
{{ `Hello ${$json.name}, your order ${$json.order_id} has shipped.` }}
{{ $json.tags.join('、') }}

n8n also provides some additional methods:

{{ $json.email.isEmail() }}
{{ $json.content.extractUrl() }}
{{ $json.title.toTitleCase() }}

Numbers

{{ $json.price * 1.05 }}
{{ Math.round($json.score * 10) / 10 }}
{{ Number($json.amount).toLocaleString('zh-TW') }}
{{ ($json.done / $json.total * 100).toFixed(1) }}%

Numbers returned by an API are sometimes strings. Convert them with Number() before calculating.

Conditionals

{{ $json.amount > 1000 ? 'VIP' : 'Regular' }}
{{ $json.nickname || $json.name }}
{{ $json.phone ?? 'Not provided' }}

To route a workflow differently based on a condition, use an If or Switch node instead of handling it in an expression.

Arrays

{{ $json.items.length }}
{{ $json.items.map(i => i.name).join(', ') }}
{{ $json.items.filter(i => i.stock === 0).length }}
{{ $json.scores.reduce((a, b) => a + b, 0) }}

Dates and times

n8n includes the Luxon date library. $now is the current time, and $today is today at midnight:

{{ $now.toFormat('yyyy-MM-dd HH:mm') }}
{{ $today.minus({ days: 1 }).toFormat('yyyy/MM/dd') }}
{{ $now.plus({ hours: 2 }).toISO() }}
{{ $now.setZone('Asia/Taipei').toFormat('MM/dd HH:mm') }}
{{ $now.weekday }}                      // 1 = Monday … 7 = Sunday

To parse a date string in your data:

{{ DateTime.fromISO($json.created_at).toFormat('yyyy-MM-dd') }}
{{ DateTime.fromFormat($json.date, 'yyyy/MM/dd').plus({ days: 7 }).toISODate() }}
{{ $json.created_at.toDateTime().diffTo($now, 'days') }}

The time zone follows the n8n or workflow time zone setting. Remember to set it to Asia/Taipei.

Common built-in variables

VariableContents
$jsonThe current item
$binaryFiles attached to the current item
$input.all()All items received by this node
$now, $todayCurrent time, today
$execution.idID of this execution
$execution.modetest (manual test) or production
$workflow.nameWorkflow name
$vars.nameCustom variable (available on some plans)
$runIndexThe number of times the node has run in this execution

Multiple lines and complex logic

You can write an immediately invoked function in an expression:

{{ (() => {
  const total = $json.items.reduce((s, i) => s + i.price * i.qty, 0);
  return total >= 1000 ? total : total + 60;
})() }}

Once the logic takes more than a few lines, consider using a Code node instead. It is easier to read and debug.

Debugging tips

  • The preview result appears immediately below an expression field. Red indicates an error.
  • The preview uses data from the last execution. Run the preceding nodes first to see a preview.
  • Cannot read properties of undefined means a level in the path does not exist. Use ?. to avoid the error: {{ $json.address?.city }}.
  • To view the entire item: {{ JSON.stringify($json) }}.

Updated October 12, 2026