#
Field Expressions
Outdated
Rule configuration documentation is not yet up to date. We have made major changes and still have the update the documentation. Please refer to our release notes for more details.
Fields within matchers can be referred to using field expressions. The following reference should give you an overview of which expressions can be used.
#
JSON Path
You can reference a field using its JSON path.
Assuming the following (partial) record
{
"source": "SOURCE_A",
"person": {
"name": "John Smith"
}
}
You can reference the source using $.source
and the name using $.person.name
.
#
Simple Path
A similar way to reference a field is by using a simple path. For the previous
example you would use source
and person.name
for referencing the fields.
While almost identical in syntax and functionality, there is a small difference when it comes to missing values. When encountering a missing field, JSON path will fail the whole expression, while the simple expression will hold an internal null value for the rest of the expression.
For example, there is no difference when referencing $.person.missing
and
person.missing
. But for more complex expressions like
$.person.missing ?? "default value"
and person.missing ?? "default value"
the first one would result in no value for that matcher (matcher will not be
satisfied if that field is required), while the latter will use default value
as the value for the matcher.
In most cases you want the behavior of JSON path. While for the example that
uses the null coalescence (??
) using JSON path would not make sense at all.
#
Complex Expressions
Beside referencing an actual value, you might want to do more advanced things like concatenating texts, doing simple math or comparing values with each other.
Here are a few examples, that use the following data.
{
"text1": "abc",
"text2": "def",
"number1": 12,
"number2": 34.5,
"list": ["g", "h", "i"],
"index1": 1,
"index2": "a"
"tokens": "aaa-bbb-ccc"
}
$.text1 + " " + $.text2
returnsabc def
($.number1 + $.number2) * 2
returns93
text2 ?? text1
returnsdef
text3 ?? text1
returnsabc
$.number1 < 10 ? $.text1 : $.text2
returnsdef
$.number1 > 10 && $.number2 < 40
returnstrue
"xyz"
returnsxyz
$.list[1]
returnsh
$([$.text1, $.text2])[$.index1]
returnsdef
$({"a": $.text1, "b": $.text2})[$.index2]
returnsabc
$(split($.tokens, "-"))[0]
returnsaaa
$(split($.tokens, "-"))[1]
returnsbbb
The following functions can be used within expressions:
split(text, delimiter)
- splits thetext
at the givendelimiter