Operators

Juttle supports these logical operators.

Operator Description
AND,and,&& Conjunctive operators

&& is short-circuiting while the others are not.

OR,or,\ \
NOT,not,! Negation operators
== Equality operator

Note =is also valid when used in filter expressions, but not in ifconditionals.

!= Inequality operator
<, <=, >, >= Is less than, is less than or equal to, is greater than, is greater than or equal to
\~, =\~ Matching operator for matching with "glob" expressions or regular expressions. See matching below
!~ Matching negation operator
in Inclusion in an array
?: Ternary operator
?? Null coalescing operator, a shortcut for a ternary operator with a null check

Matching

The ~ or ~= operators implement "glob" style wildcard matching or regular expression matching on a field. The matching used depends on the type of the literal being compared.

Glob matching is used when the operand is a string and supports wildcard characters * which matches any number of characters (even zero) and ? which matches a single character: For example:

emit
| put message="The quick brown fox"
| filter message~"*qu?ck*"

To match literal * or ?, these characters need to be escaped using \\:

emit
| put message="3*5"
| filter message~"3\\*5"

will match the message, while the following example won't:

emit
| put message="The quick brown fox"
| filter message~"\\*"

Regular expression matching is performed when the operand is a literal regular expression. For example:

emit
| put message="The quick brown fox"
| filter message~/.*[quick]+.*/

Short circuiting

Below are examples that illustrate the difference between short-circuiting and non–short-circuiting behavior.

Example: Short-circuiting

This works because if s is null, the second condition won’t be evaluated.

function isEmpty(s) {
  return s == null || String.length(s) == 0;
}

emit | put e = isEmpty(invalidField)

Example: Non-short-circuiting

This produces a type error because if s is null, the second condition will still be evaluated.

function isEmpty(s) {
  return s == null OR String.length(s) == 0;
}

emit | put e = isEmpty(invalidField)