Skip to main content
Version: latest

Expressions

An expression can contain literals, operators, and function calls.

Literal#

A single value of one of the types.

null21"valid"

Path expression#

Access a value by its name/path. For example, a given variable from the input/context.

x + y

If the value is a context (or data object/POJO,) the inner values can be accessed by context.key.

x.y// return 1 if x is {y: 1}

Also, directly on a context.

{x: 2}.x// 2
{x: {y: "valid"}}.x// {y: "valid"}
{x: {y: "valid"}}.x.y// "valid"

Inside a context, the previous values can be accessed.

{  a: 1,  b: 2,  c: a + b}

If the name or path contains any special character (e.g. whitespace, dash, etc.,) the name needs to be wrapped into single backquotes/backtick `foo bar`.

`name with whitespace`.`name+operator`

Addition#

  • Supported types: number, string, day-time-duration, year-month-duration
2 + 3// 5
"foo" + "bar"// "foobar"
duration("P1D") + duration("PT6H")// duration("P1DT6H")

Subtraction#

  • Supported types: number, time, date-time, day-time-duration, year-month-duration
5 - 3// 2
time("10:30:00") - time("09:00:00")// duration("PT1H30M")
time("10:30:00") - duration("PT1H")// time("09:30:00")

Multiplication#

  • Supported types: number, day-time-duration, year-month-duration
5 * 3// 15
3 * duration("P2Y")// duration("P6Y")

Division#

  • Supported types: number, day-time-duration, year-month-duration
6 / 2// 3
duration("P1Y") / 2// duration("P6M")
duration("P1Y") / duration("P1M")// 12

Exponentiation#

  • Supported types: number
2 ** 3// 8

Comparison#

operatorsymbolexample
equal to=x = "valid"
not equal to!=x != "valid"
less than<< 10
less than or equal<=<= 10
greater than>> 10
greater than or equal>=>= 10
betweenbetween _ and _x between 3 and 9

The operators less than, greater than, and between are only supported for:

  • Number
  • Date
  • Time
  • Date-time
  • Year-month-duration
  • Day-time-duration

Any value can be compared with null to check if it's equal to null or if it exists. Comparing null to a value different from null results in false. It returns true if the value, or the context entry (e.g. the property of a variable) is null or doesn't exist. The built-in function is defined() can be used to differentiate between a null value and a value that doesn't exist.

null = null// true
"foo" = null// false
x = null// true - if "x" is null or doesn't exist
x.y = null// true - if "x" is null, "x" doesn't exist,//           "y" is null, or "x" has no property "y"

Disjunction and conjunction#

Combine two boolean values.

true and true// true
true and false// false
true and null// null
false and null// false
true or false// true
false or false// false
true or null// true
false or null// null

If expression#

if (x < 5) then "low" else "high"

For expressions#

Iterate over a list and apply an expression (i.e. aka map). The result is again a list.

for x in [1,2] return x * 2// [2,4]

Iterate over multiple lists.

for x in [1,2], y in [3,4] return x * y// [3,4,6,8]

Iterate over a range - forward or backward.

for x in 1..3 return x * 2// [2,4,6]
for x in 3..1 return x * 2// [6,4,2]

The previous results of the iterator can be accessed by the variable partial.

for x in 1..5 return x + sum(partial)// [1,3,7,15,31]

Some/every expression#

Test if at least one element of the list satisfies the expression.

some x in [1,2,3] satisfies x > 2// true
some x in [1,2,3] satisfies x > 3// false
some x in [1,2], y in [2,3] satisfies x < y// true

Test if all elements of the list satisfies the expression.

every x in [1,2,3] satisfies x >= 1// true
every x in [1,2,3] satisfies x >= 2// false
every x in [1,2], y in [2,3] satisfies x < y// false

Filter expression#

Filter a list of elements by an expression. The expression can access the current element by item. The result is a list again.

[1,2,3,4][item > 2]// [3,4]

An element of a list can be accessed by its index. The index starts at 1. A negative index starts at the end by -1.

[1,2,3,4][1]// 1
[1,2,3,4][4]// 4
[1,2,3,4][-1]// 4
[1,2,3,4][-2]// 3
[1,2,3,4][5]// null

If the elements are contextes, the nested value of the current element can be accessed directly by its name.

[ {a: "foo", b: 5},  {a: "bar", b: 10} ][b > 7]// {a : "bar", b: 10}

The nested values of a specific key can be extracted by .key.

[ {a : "foo", b: 5 }, {a: "bar", b: 10} ].a// ["foo", "bar"]

Evaluate an enary test#

Evaluates a unary-tests expression with the given value.

x in (2..4)
x in < 3

Instance-of expression#

Checks the type of the value.

"foo" instance of number// false
"bar" instance of string// true

Functions#

Invoke a user-defined or built-in function by its name. The arguments can be passed positional or named.

add(1,2)// oradd(x:1, y:2)

A function (body) can be defined using function(arguments) expression. For example, inside a context.

{    add : function(x,y) x + y}

Special properties#

Values of type date, time, date-time, and duration have special properties to access their individual parts.

date("2017-03-10").yeardate("2017-03-10").monthdate("2017-03-10").daydate("2017-03-10").weekday
time("11:45:30+02:00").hourtime("11:45:30+02:00").minutetime("11:45:30+02:00").secondtime("11:45:30+02:00").time offset
date and time("2017-03-10T11:45:30+02:00").yeardate and time("2017-03-10T11:45:30+02:00").monthdate and time("2017-03-10T11:45:30+02:00").daydate and time("2017-03-10T11:45:30+02:00").weekdaydate and time("2017-03-10T11:45:30+02:00").hourdate and time("2017-03-10T11:45:30+02:00").minutedate and time("2017-03-10T11:45:30+02:00").seconddate and time("2017-03-10T11:45:30+02:00").time offsetdate and time("2017-03-10T11:45:30+02:00").timezone
duration("P2Y3M").yearsduration("P2Y3M").months
duration("P1DT2H10M30S").daysduration("P1DT2H10M30S").hoursduration("P1DT2H10M30S").minutesduration("P1DT2H10M30S").seconds