JSONata
Where Sommatic AI evaluates JSONata instead of JavaScript — data.transform and the conditions of flow.if and flow.switch written without braces — how to reference fields and run variables, and the differences that trip people up.
JSONata is a query and transformation language for JSON. Sommatic AI uses it where a node reshapes or tests its input: it is compact for mapping, filtering and aggregating, and it never needs a function wrapper.
Where JSONata is used
| Node | Field | When |
|---|---|---|
data.transform | expr | Always, unless you write a pure JavaScript expression that returns an object or a list. |
flow.if | expr | When the text has no double braces. |
flow.switch | expr of each case | When the text has no double braces. |
With double braces, the same fields take JavaScript expressions instead.
The input is the context
JSONata evaluates against the node’s input, so you name fields directly, without $json:
$$ is the root of the input. The run variables are available with a double dollar sign: $$json, $$execution.id,
$$workflow.slug, $$node.label. The $('Node label') accessor does not exist in JSONata: when you need another
node’s output, use a JavaScript expression with braces, or bring the data into the input first.
Transform data
In data.transform, the result of expr replaces the payload. Build the new object with JSONata’s object syntax:
Wrap a path in [ … ] when you need a list: JSONata returns a single object, not a list, when only one element
matches.
Write conditions
In flow.if, a condition without braces is JSONata:
In flow.switch, each case has a JSONata expr and the port it opens:
{
"cases": [
{ "expr": "category = \"billing\"", "port": "billing" },
{ "expr": "category = \"support\"", "port": "support" }
],
"first_match": true
}When no case matches, flow.switch leaves through default.
Differences from JavaScript
| JSONata | JavaScript |
|---|---|
= and != | === and !== |
and, or, $not(…) | The logical operators of JavaScript |
& joins strings | + |
| Strings in double quotes | Single or double quotes |
| A missing field is simply empty | Reading inside a missing field throws |
JSONata also has date functions of its own, such as $now(), which returns the current time as an ISO string in UTC.
Reference
Every JSONata function ($sum, $count, $map, $filter, $string, $exists…) is listed in the
JSONata functions reference.