On this page
Sommatic Docs
Open portal

Encoders

Base64 and URL query strings.

View as Markdown
Open in

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

$base64Encode

$base64Encode(value)

Encodes value with the URL-safe Base64 alphabet (- and _ instead of + and /) and without = padding. A string is encoded as UTF-8; any other value is serialized as JSON first. Empty values ('', null, undefined, 0, false) give an empty string.

Parameters

value string | object required
The text or value to encode.

Returns

string URL-safe Base64 text without padding.

Examples

{{ $base64Encode('Sommatic') }}
Result string
"U29tbWF0aWM"
{{ $base64Encode({ order: $json.body.order_id }) }}
Result string
"eyJvcmRlciI6Im9yZF8xMDQyIn0"
{{ $base64Encode('') }}
Result string
""

Notes

  • Some services require standard Base64 with padding (for example a Basic authorization header). Convert the result: {{ (function(){ var b = $base64Encode(text).replace(/-/g, '+').replace(/_/g, '/'); return b + '==='.slice((b.length + 3) % 4); })() }}, or bind a credential to the node instead of building the header.

In JSONata $$base64Encode(body.order_id)

$base64Decode

$base64Decode(text)

Decodes standard or URL-safe Base64, with or without padding, and returns the result as UTF-8 text. It never fails: characters outside the alphabet are skipped. To get an object back from encoded JSON, parse the text with JSON.parse.

Parameters

text string required
Base64 text.

Returns

string The decoded text; an empty string for an empty value.

Examples

{{ $base64Decode('U29tbWF0aWM') }}
Result string
"Sommatic"

Back to an object.

{{ JSON.parse($base64Decode('eyJvcmRlciI6Im9yZF8xMDQyIn0')) }}
Result object
{"order":"ord_1042"}

Notes

  • Binary content (a PDF, an image) does not survive the conversion to text: decode it in a code node or let the node that handles the file do it.

In JSONata $$base64Decode(body.state)

$toQueryString

$toQueryString(object)

Builds a query string from an object, percent-encoding keys and values. Nested objects and lists use brackets (filter[status], ids[0]), also encoded. The result starts with ?, ready to append to a URL; anything that is not an object gives an empty string.

Parameters

object object required
The parameters, one key per parameter.

Returns

string ?key=value&…, or '' when the argument is not an object.

Examples

https://api.example.com/orders{{ $toQueryString({ status: 'open', page: 2 }) }}
Result string
"https://api.example.com/orders?status=open&page=2"
{{ $toQueryString({ q: $json.body.customer.name, filter: { segment: 'gold' } }) }}
Result string
"?q=Ana%20P%C3%A9rez&filter%5Bsegment%5D=gold"
{{ $toQueryString({ ids: ['A-100', 'C-300'] }) }}
Result string
"?ids%5B0%5D=A-100&ids%5B1%5D=C-300"

false, 0 and empty strings are sent as null.

{{ $toQueryString({ active: false, retries: 0 }) }}
Result string
"?active=null&retries=null"

Notes

  • false, 0 and '' become the text null. Send them as strings ('false', '0') or write that part of the URL yourself.

In JSONata $$toQueryString({ "status": "open" })

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": "ana.perez@example.com",
      "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