# 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.

Source: https://docs.sommatic.ai/en/expressions/jsonata/ (updated 2026-11-26)

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`](https://docs.sommatic.ai/en/nodes/data.transform.md) | `expr`              | Always, unless you write a pure JavaScript expression that returns an object or a list. |
| [`flow.if`](https://docs.sommatic.ai/en/nodes/flow.if.md)               | `expr`              | When the text has no double braces.                                                     |
| [`flow.switch`](https://docs.sommatic.ai/en/nodes/flow.switch.md)       | `expr` of each case | When the text has no double braces.                                                     |

With double braces, the same fields take JavaScript [expressions](https://docs.sommatic.ai/en/expressions.md) instead.

## The input is the context

JSONata evaluates against the node's input, so you name fields directly, without `$json`:

```text
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:

```text
{
  "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:

```text
status = "active" and age >= 18
```

```text
$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

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

> **Warning: $json does not exist in JSONata**
>
> `$json.age >= 18` without braces always evaluates to false: in JSONata, `$json` is an unbound variable. Write
> `age >= 18`, or `$$json.age >= 18`, or switch to JavaScript with `{{ $json.age >= 18 }}`.

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](https://docs.sommatic.ai/en/expressions/jsonata-functions.md) reference.

## Next steps

- [JSONata functions](https://docs.sommatic.ai/en/expressions/jsonata-functions.md): The full function reference.
- [data.transform](https://docs.sommatic.ai/en/nodes/data.transform.md): Configuration and ports of the transform node.
