Skip to main content

n8n Expressions Cheat Sheet

99 copy-paste expressions for mapping data in n8n: reading fields, reaching into earlier nodes, formatting dates with Luxon, handling empty values, transforming strings and arrays, querying JSON with JMESPath, and the matching Code node patterns.

Basics: the current item

Anything between {{ and }} in a parameter field is evaluated as JavaScript. $json is the JSON of the item the node is currently processing.

  • {{ $json.email }}

    A field on the current item.

  • {{ $json["first name"] }}

    Bracket notation for keys with spaces or dashes.

  • {{ $json.customer.address.city }}

    A nested field.

  • {{ $json.items[0].sku }}

    The first element of an array field.

  • {{ $json.firstName + ' ' + $json.lastName }}

    Concatenate values.

  • {{ `Order ${$json.id} for ${$json.name}` }}

    Template literal inside an expression.

  • {{ JSON.stringify($json) }}

    The whole item as a JSON string — handy for debugging or HTTP bodies.

  • {{ $itemIndex }}

    Zero-based index of the item being processed.

  • {{ $runIndex }}

    How many times this node has run in the current execution (starts at 0).

Data from other nodes

Use $('Node Name') with the exact node name as it appears on the canvas. .item follows paired-item links back to the item that produced the current one.

  • {{ $('Webhook').item.json.body.email }}

    The matching (paired) item from an earlier node.

  • {{ $('Get Customer').first().json.id }}

    The first output item of a node.

  • {{ $('Get Customer').last().json.id }}

    The last output item of a node.

  • {{ $('Get Orders').all().length }}

    How many items a node output.

  • {{ $('Get Orders').all().map(i => i.json.total) }}

    One field from every output item, as an array.

  • {{ $('Set Config').isExecuted }}

    True if that node has run in this execution — useful after branches.

  • {{ $node["Webhook"].json.body.email }}

    Legacy syntax. Still works in older workflows, but prefer $('Node Name') in new ones.

  • {{ $prevNode.name }}

    Name of the node that passed data into the current one.

$input: this node's input

$input reads the items arriving at the current node, regardless of what the previous node is called.

  • {{ $input.item.json.email }}

    The current input item (same as $json).

  • {{ $input.first().json.email }}

    The first input item.

  • {{ $input.last().json.email }}

    The last input item.

  • {{ $input.all().length }}

    Number of input items.

  • {{ $input.all().map(i => i.json.email).join(', ') }}

    Join one field from all input items.

Dates and times (Luxon)

$now and $today are Luxon DateTime objects in the workflow's timezone. $today is midnight at the start of the current day. Format tokens are Luxon's (yyyy, MM, dd, HH, mm).

  • {{ $now.toISO() }}

    Current timestamp as ISO 8601.

  • {{ $now.toFormat('yyyy-MM-dd') }}

    Today as 2026-11-01.

  • {{ $now.toFormat('dd LLL yyyy, HH:mm') }}

    Human-readable, e.g. 01 Nov 2026, 09:30.

  • {{ $today.toFormat('yyyy-MM-dd') }}

    Start of today, formatted.

  • {{ $now.plus({ days: 7 }).toISO() }}

    One week from now.

  • {{ $now.minus({ hours: 1 }).toISO() }}

    One hour ago.

  • {{ $now.startOf('month').toISODate() }}

    First day of the current month.

  • {{ $now.endOf('week').toISODate() }}

    Last day of the current week (ISO weeks end on Sunday).

  • {{ $now.setZone('Europe/Berlin').toFormat('HH:mm') }}

    Current time in another timezone.

  • {{ $now.toMillis() }}

    Unix time in milliseconds.

  • {{ $now.toSeconds() }}

    Unix time in seconds.

  • {{ DateTime.fromISO($json.createdAt).toFormat('dd/MM/yyyy') }}

    Parse an ISO string, then format it.

  • {{ DateTime.fromSeconds($json.timestamp).toISO() }}

    Parse a Unix timestamp in seconds.

  • {{ $now.diff(DateTime.fromISO($json.dueDate), 'days').days }}

    Days between now and a date (negative if the date is in the future).

  • {{ $now.weekday }}

    Day of week, 1 (Monday) to 7 (Sunday).

Workflow, execution and variables

Metadata about the running workflow, plus instance-level values you should not hard-code.

  • {{ $execution.id }}

    ID of the current execution — useful in logs and error reports.

  • {{ $execution.mode }}

    'test' for manual runs in the editor, 'production' for active triggers.

  • {{ $execution.resumeUrl }}

    URL that resumes a workflow paused by a Wait node set to resume on webhook call.

  • {{ $workflow.name }}

    Name of this workflow.

  • {{ $workflow.id }}

    ID of this workflow.

  • {{ $workflow.active }}

    Whether the workflow is active.

  • {{ $vars.API_BASE_URL }}

    A custom Variable set in n8n. Variables are read-only in expressions and are available on plans that include them.

  • {{ $env.MY_SETTING }}

    An environment variable. Self-hosted only, and blocked when N8N_BLOCK_ENV_ACCESS_IN_NODE is true. Never use it for secrets you could store as credentials.

Conditionals and fallbacks

Keep simple logic inside the expression instead of adding an IF node for every small decision.

  • {{ $if($json.total > 100, 'priority', 'standard') }}

    $if(condition, valueIfTrue, valueIfFalse).

  • {{ $json.total > 100 ? 'priority' : 'standard' }}

    The same thing with a plain JavaScript ternary.

  • {{ $ifEmpty($json.nickname, $json.firstName) }}

    Use a fallback when the value is empty, null or undefined.

  • {{ $json.customer?.address?.city }}

    Optional chaining: returns undefined instead of throwing if a level is missing.

  • {{ $json.customer?.address?.city ?? 'Unknown' }}

    Optional chaining with a default via ??.

  • {{ $json.tags?.length > 0 }}

    Safe boolean check for a non-empty array.

  • {{ $max($json.a, $json.b, $json.c) }}

    Largest of several numbers ($min for the smallest).

String functions

Standard JavaScript string methods work, and n8n adds data transformation functions you can chain on any string.

  • {{ $json.name.toUpperCase() }}

    Upper case (toLowerCase() for lower).

  • {{ $json.name.trim() }}

    Remove surrounding whitespace.

  • {{ $json.tags.split(',') }}

    Split a comma-separated string into an array.

  • {{ $json.title.replaceAll(' ', '-') }}

    Replace every occurrence.

  • {{ $json.text.slice(0, 140) }}

    First 140 characters.

  • {{ $json.message.includes('urgent') }}

    True if the text contains a substring.

  • {{ $json.body.extractEmail() }}

    n8n: the first email address found in the text.

  • {{ $json.website.extractDomain() }}

    n8n: the domain from a URL or email.

  • {{ $json.body.extractUrl() }}

    n8n: the first URL found in the text.

  • {{ $json.email.isEmail() }}

    n8n: true if the string is a valid email address.

  • {{ $json.link.isUrl() }}

    n8n: true if the string is a URL.

  • {{ $json.notes.isEmpty() }}

    n8n: true if the string is empty (isNotEmpty() for the opposite).

  • {{ $json.html.removeTags() }}

    n8n: strip HTML tags.

  • {{ $json.title.toTitleCase() }}

    n8n: Title Case (also toSentenceCase(), toSnakeCase()).

  • {{ $json.query.urlEncode() }}

    n8n: URL-encode for query strings.

  • {{ $json.payload.base64Encode() }}

    n8n: Base64-encode (base64Decode() to reverse).

  • {{ $json.price.toNumber() }}

    n8n: convert a numeric string to a number.

  • {{ $json.dueDate.toDateTime() }}

    n8n: parse a date string into a Luxon DateTime.

Number functions

n8n adds rounding and checks to numbers; the JavaScript Math object is also available.

  • {{ $json.price.round(2) }}

    n8n: round to 2 decimal places.

  • {{ $json.score.floor() }}

    n8n: round down (ceil() to round up).

  • {{ $json.count.isEven() }}

    n8n: true for even numbers (isOdd() for odd).

  • {{ Math.max(...$json.values) }}

    Largest value in an array of numbers.

  • {{ ($json.done / $json.total * 100).toFixed(1) + '%' }}

    A percentage string.

Array and object functions

Chain these on array or object fields. Standard methods like map, filter and find work too.

  • {{ $json.orders.pluck('total') }}

    n8n: one field from each object in an array.

  • {{ $json.orders.pluck('total').sum() }}

    n8n: sum of a field across objects.

  • {{ $json.scores.average() }}

    n8n: mean of a numeric array (also max(), min()).

  • {{ $json.emails.removeDuplicates() }}

    n8n: unique values only.

  • {{ $json.list.first() }}

    n8n: first element (last() for the final one).

  • {{ $json.list.isEmpty() }}

    n8n: true if the array has no elements.

  • {{ $json.list.compact() }}

    n8n: drop empty values such as null and ''.

  • {{ $json.list.chunk(10) }}

    n8n: split into arrays of 10 elements.

  • {{ $json.a.difference($json.b) }}

    n8n: values in a that are not in b (also intersection(), union()).

  • {{ $json.items.filter(i => i.inStock).length }}

    Count matching elements with plain JavaScript.

  • {{ $json.items.find(i => i.sku === 'A-1')?.price }}

    Find one element, safely read a field.

  • {{ $json.hasField('email') }}

    n8n: true if the object has that key.

  • {{ $json.removeField('password') }}

    n8n: a copy of the object without that key.

  • {{ $json.keys() }}

    n8n: the object's keys as an array.

  • {{ Object.entries($json).length }}

    Number of top-level fields on the item.

JMESPath queries

$jmespath(object, query) runs a JMESPath query against JSON. Note the argument order: the data comes first, then the query string.

  • {{ $jmespath($json, 'people[*].name') }}

    Every name in an array of people.

  • {{ $jmespath($json, "people[?age > `30`].name") }}

    Filter, then project. Number literals use backticks.

  • {{ $jmespath($json, 'orders[0].lines[*].sku') }}

    A nested projection.

  • {{ $jmespath($json, 'length(items)') }}

    JMESPath built-in function.

Code node equivalents

Inside a Code node you write plain JavaScript — no {{ }}. The same helpers ($input, $json, $('Node'), $now, DateTime) are available. Choose the mode at the top of the node.

  • // Mode: Run Once for All Items
    const results = [];
    for (const item of $input.all()) {
      results.push({ json: { email: item.json.email.toLowerCase() } });
    }
    return results;

    Run Once for All Items: loop over $input.all() and return an array of { json } objects.

  • // Mode: Run Once for Each Item
    return {
      json: {
        ...$json,
        fullName: `${$json.firstName} ${$json.lastName}`,
      },
    };

    Run Once for Each Item: $json is the current item; return a single { json } object.

  • // Mode: Run Once for All Items
    const total = $input.all().reduce((sum, i) => sum + i.json.amount, 0);
    return [{ json: { total, count: $input.all().length } }];

    Aggregate many items into one.

  • const customer = $('Get Customer').first().json;
    return [{ json: { id: customer.id, at: $now.toISO() } }];

    Read another node's output and the current time.

  • // Mode: Run Once for All Items
    return $input.all().filter(i => i.json.status === 'paid');

    Filter items. Returning input items keeps their original structure.

FAQ

n8n expressions FAQ

What is an n8n expression?

An expression is JavaScript placed between {{ and }} in a node parameter. n8n evaluates it for each item, so {{ $json.email }} becomes the email of the item being processed. Switch a field from Fixed to Expression to type one.

What is the difference between $json and $('Node Name').item.json?

$json is the current item arriving at this node. $('Node Name').item.json reaches back to a specific earlier node and returns the item paired with the current one, which is how you combine data from several steps.

Should I use $node or $('Node Name')?

$('Node Name') is the current syntax and supports .item, .first(), .last() and .all(). $node["Node Name"] is legacy syntax that still works in older workflows, but new workflows should use $('Node Name').

Which date library does n8n use?

n8n uses Luxon. $now and $today are Luxon DateTime objects, and DateTime is available globally, so you can call methods such as toFormat, plus, minus, startOf, setZone and diff.

Why does $env not work in my workflow?

$env is only available on self-hosted n8n, and administrators can block it with the N8N_BLOCK_ENV_ACCESS_IN_NODE setting. Store secrets in credentials and shared configuration in Variables ($vars) where your plan supports them.

How do expressions differ in the Code node?

The Code node runs plain JavaScript without {{ }}. In Run Once for All Items mode you read $input.all() and return an array of { json } objects; in Run Once for Each Item mode $json is the current item and you return one { json } object.

n8n is a trademark of n8n GmbH. AltFTool is not affiliated with, endorsed by or sponsored by n8n. Community templates are credited to their creators and link to the original listing; AltFTool originals are written and tested by the AltFTool team.