Configuring Jexl operators
You can write a Jexl script as part of the configuration of many lenses. Jexl is a friendly language offering a number of operators which can be applied to transform data (typically the payload
fields ) or do comparison.
The following is a selection, for more information refer to the Jexl GitHub page.
Operators
Use these operators to perform mathematical operations on values:
Operation | Symbol | Example |
---|---|---|
Negate |
|
|
Add/Concat |
|
|
Subtract |
|
|
Multiply |
|
|
Divide |
|
|
Divide and Floor |
|
|
Modulus |
|
|
Power of |
|
|
Logical AND |
|
|
Logical OR |
`+ |
Comparisons
Use these expressions to compare two values and get a Boolean result. For example, the results can be used for filtering.
Operation | Symbol | Example |
---|---|---|
Equal |
|
|
Not Equal |
|
|
Greater Than |
|
|
Greater Than or Equal |
|
|
Less Than |
|
|
Less Than or Equal |
|
|
Element in array or string |
|
|
Conditional operators
Conditional operators return the second or third expression based on the
result of the first expression. If the first expression
("Bob" in ["Bob", "Mary"]
below) return true
, "Yes" is returned.
If it returns false, "No" is returned.
Example | Result |
---|---|
"Bob" |
"Yes" |
Identifiers
Access variables in the payload with dot notation or by using brackets For example:
{ name: { first: 'John' last: 'Smith' }, age: 55, colleagues: [ 'Mary', 'Bob', 'Ted' ], teammate: 2 }
Example | Result |
---|---|
name.first |
"John" |
colleagues[teammate] |
"Ted" |
name['la' + 'st'] |
"Smith" |
Collection filtering
Arrays of objects (Collections) can be filtered by including a filter expression in brackets. Properties of each collection can be referenced by prefixing them with a leading dot. The result is an array of objects for which the filter returns a truthy value.
{ users: [ { first: 'John', last: 'Smith', age: 20}, { first: 'Mary', last: 'Jones', age: 46}, { first: 'Ted', last: 'Cotter', age: 16}, { first: 'Bob', last: 'White', age: 66} ], adult: 21 }
Example | Result |
---|---|
users[.last == 'Jones'] |
[\{ first: 'Mary', last: 'Jones', age: 46}] |
users[.age < adult] |
[\{ first: 'John', last: 'Smith', age: 20}, first: 'Ted', last: 'Cotter', age: 16}] |
users[first == 'John'].last |
"Smith" |
Lens expression functions
In addition to the general Jexl parsing functionality, Siren Investigate
also exposes a number of JavaScript-like functions for use in lens
expressions. Payload values, or the results from earlier parsing, are
piped into the function using the |
character. These values become
the val
parameter for the functions below meaning that the val
does
not need to be added in the ()
after the function name. In some
cases, this value is all that’s needed by the function and some
functions require extra parameters.
Some functions require string inputs and some require integer or floating-point inputs
Function | Example | Explanation |
---|---|---|
|
Splits an IP address by the '.' and returns the first 3 entries as an array. |
|
|
Returns
true if |
|
|
Returns true if |
|
|
Returns
the position of the first character of |
|
|
Returns |
|
|
Returns |
|
|
Returns the string
within |
|
|
Replaces |
Function | Example | Explanation |
---|---|---|
|
Returns |
|
|
Returns the integer part of |
|
|
Returns |
|
|
Returns 1 if |
|
|
Returns the nearest integer greater than
|
|
|
Returns the nearest integer less than
|
|
|
Returns the absolute value for a
Number or 0 if the number is |
|
|
Returns |
|
|
Returns the natural logarithm of |
|
|
Returns |