JSONata Operators

JSONata Operators Introduction

A JSONata operator performs an operation on two values to produce a single result.

Fernhill SCADA supports these JSONata operators:

OperatorPriorityDescription
Multiply (*) 5 Multiplies two numbers
Divide (/) 5 Divides two numbers
Modulus (%) 5 Returns the remainder when dividing two numbers
Concatenate (&) 4 Concatenates two strings
Add (+) 4 Adds two numbers
Subtract (-) 4 Subtracts two numbers
Equal (=) 3 Tests whether two values are equal
Not Equal (!=) 3 Tests whether two values are not equal
Greater Than (>) 3 Returns true if the left value is greater than the right value
Greater Than or Equal to (>=) 3 Returns true if the left value is greater than or equal to the right value
Less Than (<) 3 Returns true if the left value is less than the right value
Less Than or Equal to (<=) 3 Returns true if the left value is less than or equal to the right value
Logical AND (and) 2 Returns true if both the left and right values are true
Logical OR (or) 1 Returns true if either left value is true, or the right value is true

Note: When multiple operators are used in an expression, the operator priority determines the order of evaluation. Higher priority operators are evaluated before lower priority operators. Equal priority operators are evaluated left to right.

Multiply (*) Operator

The multiply operator (*) adds the left and right operands to produce the numerical product. The left and right operands must be numbers. A runtime error will occur if either the left or the right operand are not numbers.

Examples

OperationResult
12 * 560
10 * 0.55

Divide (/) Operator

The divide operator (/) divides the left operand by the right operand. The left and right operands must be numbers. A runtime error will occur if either the left or the right operand are not numbers. If the right operand is zero, the return value is null.

Examples

OperationResult
12 / 52.4
10 / 0null

Modulus (%) Operator

The modulus operator (%) returns the remainder after dividing the left operand by the right operand. The left and right operands must be numbers. A runtime error will occur if either the left or the right operand are not numbers. If the right operand is zero, the return value is null.

Examples

OperationResult
12 % 52
10 % 0null

Concatenate (&) Operator

The concatenate operator (&) joins the left and right operands as strings. If either the left or right operand is not a string, it will be coerced to a string.

Examples

OperationResult
"Value=" & 5"Value=5"

Add (+) Operator

The add operator (+) adds the left and right operands to produce the numerical sum. The left and right operands must be numbers. A runtime error will occur if either the left or the right operand are not numbers.

Examples

OperationResult
12 + 517
10.5 + 11.121.6

Subtract (-) Operator

The subtract operator (-) subtracts the right operand from the left operand to produce the numerical sum. The left and right operands must be numbers. A runtime error will occur if either the left or the right operand are not numbers.

Examples

OperationResult
12 - 57
10.5 - 11.1-0.6

Equal (=) Operator

The equal operator (=) tests whether the left and right operands are the same type and value. If either the left operand, or the right operand, are invalid selectors, the operation returns false. If the left and right operands are different types, the operation returns false.

Examples

OperationResult
null = nulltrue
false = truefalse
false = falsetrue
12 = 5false
12 = 12true
\"12\" = 12false

Not Equal (!=) Operator

The not equal operator (!=) tests whether the left and right operands are different types or different values. If either the left operand, or the right operand, are invalid selectors, the operation returns false. If the left and right operands are different types, the operation returns true.

Examples

OperationResult
null != nullfalse
false != truetrue
false != falsefalse
12 != 5true
12 != 12false
\"12\" != 12true

Greater Than (>) Operator

The greater than operator (>) returns true if the left operand is greater than the right operand. If either the left operand, or the right operand, are invalid selectors, the operation returns false. The left and right operands must be both numbers or both strings.

Examples

OperationResult
12 > 5true
12 > 12false
12 > 17false
\"This\" > \"That\"true

Greater Than or Equal to (>=) Operator

The greater than or equal to operator (>=) returns true if the left operand is greater than or equal to the right operand. If either the left operand, or the right operand, are invalid selectors, the operation returns false. The left and right operands must be both numbers or both strings.

Examples

OperationResult
12 >= 5true
12 >= 12true
12 >= 17false
\"This\" >= \"That\"true

Less Than (<) Operator

The less than operator (<) returns true if the left operand is less than the right operand. If either the left operand, or the right operand, are invalid selectors, the operation returns false. The left and right operands must be both numbers or both strings.

Examples

OperationResult
12 < 5false
12 < 12false
12 < 17true
\"This\" < \"That\"false

Less Than or Equal to (<=) Operator

The less than or equal to operator (<=) returns true if the left operand is less than or equal to the right operand. If either the left operand, or the right operand, are invalid selectors, the operation returns false. The left and right operands must be both numbers or both strings.

Examples

OperationResult
12 <= 5false
12 <= 12true
12 <= 17true
\"This\" <= \"That\"false

Logical AND (and) Operator

The Logical AND operator returns true if both the left and right values are true.

Examples

OperationResult
false and falsefalse
false and truefalse
true and falsefalse
true and truetrue
1 and 0false
1 and 1true

Logical OR (or) Operator

The Logical OR operator returns true if either the left or right values are true.

Examples

OperationResult
false or falsefalse
false or truetrue
true or falsetrue
true or truetrue
0 or 0false
1 or 0true

Further Information

Fernhill SCADA JSONata

To learn more about the supported features of JSONata in Fernhill SCADA.

Glossary

For the meaning of terms used in Fernhill SCADA.