# Field Expressions

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 returns abc def
  • ($.number1 + $.number2) * 2 returns 93
  • text2 ?? text1 returns def
  • text3 ?? text1 returns abc
  • $.number1 < 10 ? $.text1 : $.text2 returns def
  • $.number1 > 10 && $.number2 < 40 returns true
  • "xyz" returns xyz
  • $.list[1] returns h
  • $([$.text1, $.text2])[$.index1] returns def
  • $({"a": $.text1, "b": $.text2})[$.index2] returns abc
  • $(split($.tokens, "-"))[0] returns aaa
  • $(split($.tokens, "-"))[1] returns bbb

The following functions can be used within expressions:

  • split(text, delimiter) - splits the text at the given delimiter