On this page
Sommatic Docs
Open portal

Helpers

Defaults for empty values, slugs, JMESPath queries and lodash.

View as Markdown
Open in

Each example was run against the deployed expression engine over the example context at the end of the page.

$ifEmpty

$ifEmpty(value, fallback)

Returns fallback when value is undefined, null, an empty string '', an empty list or an object without keys. Any other value is returned as it is: 0, false and a string of spaces are kept.

Parameters

value any required
The value to check, usually a read that may be missing.
fallback any required
What to return when value is empty. Any type.

Returns

any value or fallback, with its own type.

Examples

An empty string takes the fallback.

{{ $ifEmpty($json.body.priority, 'normal') }}
Result string
"normal"
{{ $ifEmpty($json.body.customer.phone, 'no phone') }}
Result string
"no phone"

A node that did not run.

{{ $ifEmpty($('Approval').item.json.decision, 'pending') }}
Result string
"pending"

0 is not empty.

{{ $ifEmpty(0, 10) }}
Result number
0
{{ $ifEmpty([], ['none']) }}
Result list
["none"]

Notes

  • To also replace 0 or false, use ||: {{ $json.body.retries || 3 }}. To replace only null and undefined, use ??.

In JSONata $$ifEmpty(body.priority, "normal")

$slugify

$slugify(text)

Turns any text into kebab case (lodash kebabCase): lowercase words joined by hyphens, accents removed, punctuation dropped. Words are also split where the case changes and between letters and digits, so helloWorld ABC123 becomes hello-world-abc-123.

Parameters

text any required
Converted to text first: null becomes 'null'.

Returns

string The slug; an empty string for empty text.

Examples

{{ $slugify('Hola Mundo Ñandú 2026') }}
Result string
"hola-mundo-nandu-2026"
{{ $slugify($json.body.customer.name) }}
Result string
"ana-perez"
{{ $slugify('helloWorld ABC123') }}
Result string
"hello-world-abc-123"

Notes

  • Guard missing values first: $slugify($ifEmpty($json.title, 'untitled')).

In JSONata $$slugify(body.customer.name)

$jmespath

$jmespath(data, query)

Runs a JMESPath query over data and returns what it selects: a value, a list or an object. A query is often shorter than the JavaScript for deep responses: filters ([?qty > \0`]), projections ([*].sku) and functions (length, sort_by, max_by`). Literals go between backticks inside the query.

Parameters

data any required
The value to query, usually $json or a node's output.
query string required
A JMESPath expression. Write it between single quotes so the backticks and double quotes inside it need no escaping.

Returns

any What the query selects; null when nothing matches.

Examples

{{ $jmespath($json.body, 'items[?qty > `0`].sku') }}
Result list
["A-100","C-300"]
{{ $jmespath($json.body, 'length(items)') }}
Result number
3
{{ $jmespath($json.body, 'max_by(items, &price).sku') }}
Result string
"C-300"
{{ $jmespath($json.body, 'items[*].{ id: sku, units: qty }') }}
Result list
[
  {
    "id": "A-100",
    "units": 2
  },
  {
    "id": "B-200",
    "units": 0
  },
  {
    "id": "C-300",
    "units": 1
  }
]

A path that does not exist gives null, not an error.

{{ $jmespath($json.body, 'shipping.address.city') }}
Result null
null

A literal without backticks is a syntax error.

{{ $jmespath($json.body, 'items[?qty > 0]') }}
Throws
Invalid token (Number): "0"

Errors

Message Cause and fix
Invalid token (<type>): "<value>" The query is not valid JMESPath, often a number or a string literal without backticks.

In JSONata $$jmespath($$json, "body.items[0].sku")

_

_

The full lodash library. It is the shortest way to group, sum, pick, deduplicate and read deep paths with a default.

Examples

{{ _.sumBy($json.body.items, 'qty') }}
Result number
3
{{ _.uniq($json.body.tags) }}
Result list
["new","web"]
{{ _.get($json, 'body.shipping.city', 'unknown') }}
Result string
"unknown"
{{ _.pick($json.body, ['order_id', 'email']) }}
Result object
{"order_id":"ord_1042","email":"[email protected]"}
{{ _.keyBy($json.body.items, 'sku') }}
Result object
{
  "A-100": {
    "sku": "A-100",
    "qty": 2,
    "price": 10.5
  },
  "B-200": {
    "sku": "B-200",
    "qty": 0,
    "price": 4
  },
  "C-300": {
    "sku": "C-300",
    "qty": 1,
    "price": 25
  }
}

Notes

  • Every function with its parameters, return value and examples is in the lodash reference.

In JSONata Not available in JSONata, which has its own function library.

Example context

The examples run over this data: the input of the current node ($json), the nodes that already ran ($(…)), the ids of the run and the current node. The clock is fixed at 2026-11-26T14:30:00.000Z and the server zone is UTC, so $now and $today give the same values on every page.

Input of the current node JSON
{
  "$json": {
    "body": {
      "order_id": "ord_1042",
      "email": "[email protected]",
      "customer": {
        "name": "Ana Pérez",
        "segment": "gold"
      },
      "priority": "",
      "items": [
        {
          "sku": "A-100",
          "qty": 2,
          "price": 10.5
        },
        {
          "sku": "B-200",
          "qty": 0,
          "price": 4
        },
        {
          "sku": "C-300",
          "qty": 1,
          "price": 25
        }
      ],
      "tags": [
        "new",
        "web",
        "new"
      ],
      "created_at": "2026-11-25T09:15:00Z"
    },
    "headers": {
      "content-type": "application/json"
    },
    "query": {},
    "method": "POST"
  }
}
Nodes that already ran (label → output) JSON
{
  "Webhook Receiver": "= $json",
  "Normalize input": {
    "correlation_id": "c-7f3a",
    "channel": "web"
  },
  "Classify": {
    "label": "billing",
    "confidence": 0.92
  }
}
Run and current node JSON
{
  "$execution": {
    "id": "fir-xxxx",
    "flow_instance_id": "fi-xxxx",
    "flow_definition_id": "fd-xxxx",
    "flow_version_id": "fv-xxxx",
    "flow_slug": "order-intake"
  },
  "$node": {
    "id": "node-notify",
    "label": "Notify customer"
  }
}

Examples run against the orchestrator at commit 31e874b

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