Operators
Math and equality
Section titled “Math and equality”Jolt implements addition, subtraction, multiplication, and division (+, -, *, /), along with comparison and equality (==, !=, >, >=, <, <=). Operations can be parenthesized, and method results can be operands.
{ "first": 5, "second": 4, "third": 3, "fourth": 2, "fifth": 1}{ "result": "#valueOf($.first) * #valueOf($.second) - #valueOf($.third) + #valueOf($.fourth) / #valueOf($.fifth) == 19"}{ "result": true}String concatenation
Section titled “String concatenation”+ is overloaded to concatenate strings, whether they come from the source document or are literals.
{ "value": "example"}{ "result": "#valueOf($.value) + #valueOf($.value) + 'hello'"}{ "result": "exampleexamplehello"}Logical operators
Section titled “Logical operators”&& and || take boolean operands and return a boolean.
||returnstrueif at least one operand istrue, short-circuiting at the firsttrue.&&returnstrueonly if both operands aretrue, short-circuiting at the firstfalse.
{ "first": true, "second": false, "third": true}{ "orResult": "#valueOf($.first) || #valueOf($.second) || #valueOf($.third)", "andResult": "#valueOf($.first) && #valueOf($.second) && #valueOf($.third)", "combinedResult": "(#valueOf($.first) && #valueOf($.second)) || #valueOf($.third)"}{ "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"}Logical NOT
Section titled “Logical NOT”! negates a boolean value.
{ "notFirst": "!#valueOf($.first)", "notSecond": "!#valueOf($.second)"}Null-handling operators
Section titled “Null-handling operators”?? (null-coalescing) and ?. (null-safe dereferencing) are covered in null handling.
Precedence
Section titled “Precedence”See the operator precedence table for how mixed expressions are grouped.
