Prerequisites
In this article you'll learn:
The Logic node transforms the input data of your pipeline with a JSONata expression. JSONata is a query and transformation language for JSON. With one expression you can reshape objects, compute values, filter lists, and extract parts of strings with regular expressions.
The node evaluates your JSONata expression against the input data and outputs the result of the expression. The result can be an object, a list, or a single value, and subsequent nodes can access it like the output of any other node.
Your expression reads the input data through these paths:
data — the output of the previous node.trigger — the data captured by the flow's trigger.loop_1 or mysql_1 —
the full output of that node, so mysql_1.data is its data.For example, when the previous node outputs:
{
"customer": {"name": "Jane", "email": "jane@example.com"},
"orders": [
{"id": "A-1", "total": 40},
{"id": "A-2", "total": 60}
]
}
the expression
{
"name": data.customer.name,
"order_count": $count(data.orders),
"total_spent": $sum(data.orders.total)
}
outputs:
{
"name": "Jane",
"order_count": 2,
"total_spent": 100
}
JSONata contains regular expression functions, so you do not need a separate
node to extract a part of a string. Use $match to extract and $replace to
substitute:
$match(data.subject, /ORD-(\d+)/).groups[0]
extracts 1234 from a subject line like Question about ORD-1234, and
$replace(data.phone, /[^\d+]/, "")
removes everything except digits and + from a phone number.
See the JSONata documentation on regular expressions for the full function reference.
Patterns run on Google's RE2 engine, which
matches in guaranteed linear time, so a complex pattern cannot slow down your
pipeline. Because of how RE2 achieves this guarantee, backreferences and
lookahead/lookbehind assertions (for example (?=...)) are not supported;
a pattern that uses them produces an expression error.
An API returns a deeply nested response, but your template only needs a few fields. Build a flat object with just those fields so the template stays simple.
Sum order totals, count items, or format a date with JSONata's
built-in functions like $sum, $count,
and $fromMillis.
Pull an order number or ticket reference out of an email subject with
$match, then use the extracted value in a later SQL or REST API node.
When the expression fails — for example because of a syntax error — the behavior depends on how the flow runs:
{} and the flow
continues, so one broken expression does not stop your data pipeline.An expression that references a path that does not exist in the input data
also outputs {}.
Evaluation is limited to a few seconds per run; an expression that loops forever is stopped and treated like an error.