n8n Expressions Explained: How Items Work and the Mistakes That Break Them
By Abhishek Patoliya · 2026-08-16
Expressions are the small pieces of JavaScript-like code inside {{ }} that fill n8n node parameters with data from the workflow: {{ $json.email }}, {{ $now.toISO() }}, {{ $('Fetch customer').item.json.plan }}. Nearly every "my expression is empty" or "Cannot read properties of undefined" problem comes from a handful of misunderstandings about which data an expression can see. This lesson explains that model first, then the mistakes it prevents.
Before you start: you should be comfortable reading JSON (JSON for automation builders). Syntax below follows n8n's expression reference as of 9 November 2026.
The model: items, and where an expression looks
Data moves through n8n as a list of items, each holding a JSON object. A node with an expression evaluates it once per input item. Within that evaluation:
| Write | To get |
$json | The JSON of the current input item, i.e. what the previous node sent for this item |
$input.item, $input.first(), $input.last(), $input.all() | The current node's input: this item, the first, the last, or all of them |
$('Node name').item | The item in that earlier node that this item came from (its "paired item") |
$('Node name').first(), .last(), .all() | That node's first, last or all output items, regardless of pairing |
$now, $today | The current date-time and today's date, as Luxon DateTime objects |
Add .json.field to an item to read a field: $('Fetch customer').item.json.email.
Mistake 1: reading $json for a field an earlier node had
$json only sees what the immediately previous node passed in. If node A produced customerEmail but node B (an HTTP request, say) replaced the item with its API response, {{ $json.customerEmail }} in node C is empty. Reach back to the node that has it:
{{ $('Fetch customer').item.json.customerEmail }} // the matching item from that node
{{ $('Settings').first().json.apiRegion }} // a single settings item used by every item
Use .item when each item has its own counterpart in the earlier node (n8n follows the paired-item link); use .first() for a one-item node such as a settings lookup. You'll still find the older $node["Fetch customer"].json form in old workflows and forum answers; the current reference uses $(), so write new expressions that way. When .item can't find the pairing (common after Code nodes or merges), see paired items explained.
Mistake 2: assuming a field always exists
Test data is tidy; live data has missing fields. Guard optional paths:
{{ $json.customer?.address?.city ?? "Unknown" }} // JavaScript optional chaining + default
{{ $ifEmpty($json.phone, "not provided") }} // n8n helper: treats null, undefined, "", [] and {} as empty
?? only replaces null and undefined; an empty string passes through. $ifEmpty also catches empty strings, arrays and objects, which is usually what you want for form and API data.
Mistake 3: referencing a node that didn't run on this path
After an IF or Switch node, a node on the other branch produced nothing in this execution, so $('That node') has no data and the expression errors. It works in testing because you tested the branch where it ran. For every named-node reference after a branch, ask: is this node guaranteed to have run on every path that reaches here? If not, restructure (merge the branches first, or move the lookup before the split).
Mistake 4: numbers that are really strings
APIs, forms and spreadsheets often send numbers as strings. JavaScript then does surprising things:
"10" + 5 // "105" (concatenation, not 15)
"42" === 42 // false
Number("42") === 42 // true
Number("") // 0, not NaN: an empty field silently becomes zero
Number("abc") // NaN
Convert explicitly where you compare or calculate ({{ Number($json.qty) * $json.price }}), and check for empty input before converting, so a missing quantity doesn't become 0. In Edit Fields, setting the field's type does the conversion for you (next lesson).
Mistake 5: hand-formatting dates
$now and $today are Luxon DateTime objects with methods, so you rarely need string tricks:
{{ $now.toISO() }} // full ISO timestamp
{{ $now.plus({ days: 7 }).toISO() }} // a week from now
{{ $today.minus({ months: 1 }).startOf('month').toISO() }} // start of last month
{{ $now.setZone('Europe/Paris').toISO() }}
$now follows the workflow's time zone setting. In a Code node, Luxon is plain Luxon, so n8n-specific helpers aren't available there and you use Luxon's own methods such as toFormat(). Time zone pitfalls are covered in dates, times and time zones.
Mistake 6: doing whole-list work in a per-item expression
Because an expression runs once per item, "total of all orders" or "does any item have status=failed?" doesn't belong in a normal field expression. Use the Aggregate node, a Summarize node, or a Code node set to run once for all items, which can use $input.all(). If a value must be identical for every item (a batch ID, a run timestamp), compute it once in an earlier node and carry it on each item.
Debugging an expression
- Read the preview. The expression editor evaluates against the current input as you type. Check it with a real item, including one with missing fields.
- Read the error literally. "Cannot read properties of undefined (reading 'city')" means the part before
.city is missing.
- Check the item count. A node with 0 input items evaluates nothing, so an "empty" result may mean the previous node returned no items.
- Keep expressions short. More than one fallback or any real branching belongs in an IF node or a small Code node, where you can name variables and log values.
Key takeaways
$json is the current input item only; reach earlier nodes with $('Node').item or .first().
- Guard optional fields with
?., ?? or $ifEmpty.
- A node on an unexecuted branch has no data; don't reference it after a split.
- Convert strings to numbers explicitly, and remember
Number("") is 0.
- Use Luxon methods on
$now and $today for dates; use aggregate nodes or a Code node for whole-list logic.
Exercise: in a workflow with a Manual Trigger, an Edit Fields node producing {"customer": {"name": "Ada"}, "qty": ""}, and an HTTP Request in between, write expressions that read the customer's city with a default, the quantity as a number that becomes "missing" when empty, and a due date 14 days from today. Next lesson: Edit Fields (Set).
References (checked 9 November 2026)
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.