A single JSONPath match is unwrapped unless the path selects many
Arity is read off the path, not off the result, so a query written to select many keeps a list shape even on the day it matches exactly one thing.
The rule
- A JSONPath query that returns exactly one match MUST yield that match rather than a one-element array, unless the path is written to select many, containing a wildcard, a filter or a slice.
- A path written to select many MUST yield an array, even when only one item matched.
What it means
Whether a result comes back as a bare value or as an array is decided by reading the query's own syntax, not by counting how many things it happened to match today. A query with no wildcard, filter or slice in it is written to find one thing, so a single match is handed back directly. A query that carries one of those — even when, on a given record, it only ever matches one item — keeps its array shape regardless, because the query was written to select many and the day it matches one is not a promise it always will.
Example
Two queries against the same stored data: $.store.name, an ordinary path,
and $.store.books[?(@.price < 9)].title, a filter written to select many —
each matching exactly one item.
"Test Store"["Book 3"]Why
Recorded under OPEN-25.