Skip to content

Operators

Jolt implements addition, subtraction, multiplication, and division (+, -, *, /), along with comparison and equality (==, !=, >, >=, <, <=). Operations can be parenthesized, and method results can be operands.

source.json
{
"first": 5,
"second": 4,
"third": 3,
"fourth": 2,
"fifth": 1
}
transformer.json
{
"result": "#valueOf($.first) * #valueOf($.second) - #valueOf($.third) + #valueOf($.fourth) / #valueOf($.fifth) == 19"
}
output.json
{
"result": true
}

+ is overloaded to concatenate strings, whether they come from the source document or are literals.

source.json
{
"value": "example"
}
transformer.json
{
"result": "#valueOf($.value) + #valueOf($.value) + 'hello'"
}
output.json
{
"result": "exampleexamplehello"
}

&& and || take boolean operands and return a boolean.

  • || returns true if at least one operand is true, short-circuiting at the first true.
  • && returns true only if both operands are true, short-circuiting at the first false.
source.json
{
"first": true,
"second": false,
"third": true
}
transformer.json
{
"orResult": "#valueOf($.first) || #valueOf($.second) || #valueOf($.third)",
"andResult": "#valueOf($.first) && #valueOf($.second) && #valueOf($.third)",
"combinedResult": "(#valueOf($.first) && #valueOf($.second)) || #valueOf($.third)"
}
output.json
{
"orResult": true,
"andResult": false,
"combinedResult": true
}

&& binds tighter than ||, so combinedResult would be true even without the parentheses.

Because the right operand is skipped when the left one decides the result, the left operand can guard the right one. Here the comparison runs only when $.discount exists, so a missing value gives false instead of an error:

{
"hasDiscount": "#exists($.discount) && #valueOf($.discount) > 0"
}

! negates a boolean value.

{
"notFirst": "!#valueOf($.first)",
"notSecond": "!#valueOf($.second)"
}

?? (null-coalescing) and ?. (null-safe dereferencing) are covered in null handling.

See the operator precedence table for how mixed expressions are grouped.