Overview of Paths in SODA Filter
A filter specification contains zero or more paths to fields in JSON documents. A path to a field can have multiple steps, and it can cross the boundaries of objects and arrays.
(In the context of a filter, the term “path to a field” is sometimes shortened informally to “field”.)
For example, this filter matches all JSON documents where a zip field exists under field address and has value 94088:
{ "address.zip" : 94088 }
The path in the preceding filter is address.zip, which matches Example 2-1.
Note: A SODA filter is itself a JSON object. You must use strict JSON syntax in a filter. In particular, you must enclose all field names in double quotation marks ("). This includes field names, such as address.zip, that act as SODA paths. For example, you must write {"address.zip": 94088}, not {address.zip : 94088}.
Paths can target a particular element of an array in a JSON document, by enclosing the array position of the element in square brackets ([ and ]).
For example, path address[1].zip targets all zip fields in the second object of array addresses. (Array position numbers start at 0, not 1.) The following filter matches Example 2-2 because the second object of its address array has a zip field with value 90001.
{ "address[1].zip" : 90001}
Instead of specifying a single array position, you can specify a list of positions (for example, [1,2]) or a range of positions (for example, [1 to 3]). The following filter matches Example 2-3 because it has "soda" as the first element (position 0) of array drinks.
{ "drinks[0,1]" : "soda" }
And this filter does not match any of the sample documents because they do not have "soda" as the second or third array element (position 1 or 2).
{ "drinks[1 to 2]" : "soda" }
If you do not specify an array step then [*] is assumed, which matches any array element — the asterisk, *, acts as a wildcard. For example, if the value of field drinks is an array then the following filter matches a document if the value of any array element is the string "tea":
{"drinks" : "tea"}
This filter thus matches sample documents 1 and 2. An equivalent filter that uses the wildcard explicitly is the following:
{"drinks[*]" : "tea"}
See Also: Oracle Database JSON Developer’s Guide for information about strict and lax JSON syntax
Related Topics