On this page
Sommatic Docs
Open portal

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.

View as Markdown
Open in

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

NodeFieldWhen
data.transformexprAlways, unless you write a pure JavaScript expression that returns an object or a list.
flow.ifexprWhen the text has no double braces.
flow.switchexpr of each caseWhen 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:

customer.email
items[price > 50]
$sum(items.price)

$$ 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:

{
  "order": id,
  "customer": customer.email,
  "lines": [items.{ "sku": sku, "total": qty * price }],
  "total": $sum(items.(qty * price)),
  "run": $$execution.id
}

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:

status = "active" and age >= 18
$exists(customer.email) and $count(items) > 0

In flow.switch, each case has a JSONata expr and the port it opens:

JSON
{
  "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

JSONataJavaScript
= and !==== and !==
and, or, $not(…)The logical operators of JavaScript
& joins strings+
Strings in double quotesSingle or double quotes
A missing field is simply emptyReading 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.

Next steps

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs