Skip to content

JSONata

When a state machine (or a state) sets "QueryLanguage": "JSONata", field values may contain JSONata expressions. Stegflow evaluates them with the Jsonata.Net.Native library, a .NET port of JSONata.

This page covers the basics of what you can write. For the full expression and function language, use the upstream references:

Writing an expression

A JSONata expression is wrapped in {% %}. Anywhere a field takes a value, you can compute it:

{
  "QueryLanguage": "JSONata",
  "StartAt": "Greet",
  "States": {
    "Greet": {
      "Type": "Pass",
      "Output": "{% 'Hello, ' & $states.input.name %}",
      "End": true
    }
  }
}

A string without the {% %} markers is treated as a literal, not evaluated.

The $states context

Inside an expression, the reserved $states object exposes the runtime data:

Reference Available in Description
$states.input everywhere The state input.
$states.context everywhere The execution context object (execution name, state machine, task token, and so on).
$states.result after a task/output step The result produced by the state.
$states.errorOutput inside a Catch The error and cause of the caught failure.

Variables

Values set with Assign become variables, referenced with a leading $:

{
  "Type": "Pass",
  "Assign": { "total": "{% $states.input.a + $states.input.b %}" },
  "Next": "UseIt"
}

Later states read it as {% $total %}.

What you can use

Everything the JSONata language offers is available: path navigation, arithmetic and comparison operators, string and array manipulation, conditional (? :) and block expressions, and the full built-in function library ($sum, $map, $filter, $substring, $now, and so on). Refer to the JSONata function library for the complete list.

Port differences

Because Stegflow uses a .NET port rather than the reference JavaScript implementation, a small number of functions may behave slightly differently or be unavailable. When in doubt, check the Jsonata.Net.Native project.