Logical operators
Logical operators used in transformations for Omnidocs Create Classic.
Comparison operators
These mathematical operators take two arguments, one on each side of the symbol, and return true if the expression is true and false otherwise. The following operations are supported:
==, tests for equality.!=, tests for inequality.<, less than.<=, less than or equal to.>, greater than.>=, greater than or equal to.
Note that == and != are valid for inputs of any data types, but the other operators are limited to numbers and strings. Strings are compared alphabetically.
In the following example, the data contains input pairs and the map function applies the operator to each input pair. The output is a list of results in the same order.
{
"compare": [
[1, 1],
[1, 2],
["ab", "cde"],
[null, null],
[{}, {}],
[[1], [1, 2]]
]
}{
equality: map(&@[0]==@[1], compare), // is 1==1?
inequality: map(&@[0]!=@[1], compare), // is 1!=1?
lessThan: map(&@[0]<@[1], compare), // is 1<1?
lessThanOrEqual: map(&@[0]<=@[1], compare), // is 1<=1?
greaterThan: map(&@[0]>@[1], compare), // is 1>1?
greaterThanOrEqual: map(&@[0]>=@[1], compare) // is 1>=1?
}{
"equality": [true, false, false, false, true, false],
"inequality": [false, true, true, true, false, true],
"lessThan": [false, true, true, null, null, null],
"lessThanOrEqual": [true, true, true, null, null, null],
"greaterThan": [false, false, false, null, null, null],
"greaterThanOrEqual": [true, false, false, null, null, null]
}Logical operators
There are three logical operators in JMESPath, from weakest to strongest precedence:
- or:
|| - and:
&& - unary not:
!
|| and && take two expressions as parameters, one on each side of the operator, denoted as &left and &right.
The result of the or expression is either &left or &right. If &left is truthy, return &left. Otherwise, return &right. As a result, || returns a truthy value if one of the arguments is truthy and a falsy value otherwise.
The result of the and expression is either &left or &right. If &left is falsy, return &left. Otherwise, return &right. As a result, && returns a truthy value if both arguments are truthy and a falsy value otherwise.
! takes one argument and returns the truth value opposite to the truth value of the argument.
{
a: `{}` || `null`,
b: `null` || `1`,
c: '' && `1`,
d: !`true`,
e: `false` || `true`,
f: `false` && `true`,
g: !'true' || !`123`,
h: `[]` || `null`
}{
"a": null,
"b": 1,
"c": "",
"d": false,
"e": true,
"f": false,
"g": {},
"h": null
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article