Skip to content

Nested Fields & Array Values

Sébastien Cottinet edited this page Jun 9, 2021 · 1 revision

The examples in the previous pages show how to test for scalar fields at the root of a document, but it is also possible to test nested properties or array values.

Nested properties

To test for a nested property, a path to it must be supplied, in the following manner: path.to.property

Example

Given the following document:

{
    "name": {
        "first": "Grace",
        "last": "Hopper"
    }
}

Here is a filter, testing equality on the field last in the name sub-object:

{
    "equals": {
        "name.last": "Hopper"
    }
}

Array values

A few keywords, like exists or missing, allow searching for array values.

These values can be accessed with the following syntax: <array path>[<value>]
Only one array value per exists/missing keyword can be searched in this manner.

Array values must be scalars (strings, numbers, booleans or null), following JSON format:

  • Strings: the value must be enclosed in double quotes. Example: foo["string value"]
  • Numbers, booleans and the null value must be used as is. Examples: foo[3.14], foo[false], foo[null]

Array values can be combined with nested properties: nested.array["value"]

Example

Given the following document:

{
    "name": {
        "first": "Grace",
        "last": "Hopper",
        "hobbies": ["compiler", "COBOL"]
    }
}

Here is a filter, testing whether the value compiler is listed in the array hobbies:

{
    "exists": "name.hobbies[\"compiler\"]"
}
Clone this wiki locally