Descendant Operator
In addition to providing an explicit path to reach the zip
field, it may sometimes be useful to reference the zip
field without knowing the full path. In such a case, we can use the descendant
operator (//
) instead of the child
operator (/
). To reach the same zip
field as above, we can accomplish this by simply using the path //zip
.
There is a very important distinction, though, between the child
operator and the descendant
operator: the descendant
operator may match many fields, whereas the child
operator will match at most one field. To help understand this, consider the following Record:
{
"name": "John Doe",
"workAddress": {
"number": "123",
"street": "5th Avenue",
"city": "New York",
"state": "NY",
"zip": "10020"
},
"homeAddress": {
"number": "456",
"street": "116th Avenue",
"city": "New York",
"state": "NY",
"zip": "11697"
}
}
Now, if we use the RecordPath /workAddress/zip
, we will be referencing the zip
field that has a value of "10020." The RecordPath /homeAddress/zip
will reference the zip
field that has a value of "11697." However, the RecordPath //zip
will reference both of these fields.