-
Notifications
You must be signed in to change notification settings - Fork 5
Nested Fields & Array Values
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.
To test for a nested property, a path to it must be supplied, in the following manner: path.to.property
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"
}
}
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"]
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\"]"
}