Recipes
Expression patterns that work in production workflows — reading earlier nodes, building typed objects, defensive conditions, dates in a time zone, safe URLs, defaults and lists — ready to copy into a node field.
Each recipe says which field kind it needs: pure (the whole field is the expression and keeps its type) or mixed (text around the expression, the result is text). Replace the node labels with the labels of your workflow.
Read a field from an earlier node
Pure or mixed. The most common expression in production:
{{ $('Normalize input').item.json.correlation_id }}Read the webhook request
Right after a webhook trigger, the request is the input ($json). Further down, read it from the trigger by label:
{{ $json.body.email }}
{{ $('Webhook Receiver').item.json.body.email }}
{{ $('Webhook Receiver').item.json.query.source }}Build a typed object
Pure. Wrap object literals in parentheses, otherwise the braces are read as a block of code:
{{ ({ id: $json.id, received: $now.toISO(), run: $execution.id }) }}Use it for a request body, the output of a data.transform or the payload of a task.
Write a defensive condition
Pure, for flow.if. When the data you read may be missing, wrap the logic in a function that you
call at once, and return false if anything fails:
{{ (function () { try { var result = $('Classify').item.json || {}; return (result.confidence || 0) >= 0.7; } catch (error) { return false; } })() }}For short checks, optional chaining is enough:
{{ ($('Classify').item.json.confidence ?? 0) >= 0.7 }}Format dates in a time zone
Pure or mixed. $now uses the server’s zone; set yours first:
{{ $now.setZone('America/Bogota').toFormat('yyyy-LL-dd HH:mm') }}
{{ $now.setZone('America/Bogota').plus({ days: 3 }).toISODate() }}
{{ $today.minus({ months: 1 }).toFormat('LLLL yyyy') }}Build safe URLs
Mixed. Encode every value that goes into a path or query:
https://api.example.com/items/{{ encodeURIComponent($json.key) }}
https://api.example.com/search{{ $toQueryString({ q: $json.body.term, page: 1 }) }}Fall back to a default
Pure or mixed:
{{ $ifEmpty($json.body.priority, 'normal') }}
{{ $json.customer?.name ?? 'Customer' }}Filter, map and sum lists
Pure:
{{ $json.items.filter(item => item.qty > 0).map(item => item.sku) }}
{{ _.sumBy($json.items, 'qty') }}
{{ $jmespath($json, 'items[?status == `open`].id') }}Use an optional branch
Pure. Read a node only if it ran in this execution:
{{ $('Enrich customer').isExecuted ? $('Enrich customer').item.json.segment : 'unknown' }}Put a traceable reference in a message
Mixed. $execution.id is shared by every run of a workflow.chain, so one reference follows the whole case:
We received your request. Reference: {{ $execution.id }}Read the result of a code node
code.js and code.python wrap what they return in result:
{{ $('Compute totals').item.json.result.total }}Join values into one piece of text
When a field would start and end with an expression, write a single expression that concatenates:
{{ $json.first_name + ' ' + $json.last_name }}
{{ `${$json.prefix}-${$json.number}` }}