Skip to content

Only a $-rooted JSONPath query unwraps a list to its first match

The rule

Normative: this is the rule
  1. An extractor MUST reduce an array result to its first match where its engine is jsonpath, the path is $-rooted, and extract-all is off.
  2. It MUST NOT reduce an array result otherwise.
  3. A property-path engine MUST deliver an array result whole, even for a $-prefixed path.
  4. A jsonpath engine that falls back to property-path resolution MUST NOT unwrap.
  5. The extractor's reported JSONPath flag MUST report the $ prefix alone.
  6. It MUST NOT depend on the engine in force.

What it means

Whether an array result gets reduced to its first match turns on which engine ran, not on what the path string looks like. A $-rooted path evaluated by the property-path engine is still read as a property path — the leading $ is not enough on its own to trigger the reduction. The flag that reports whether the path looked like a JSONPath query is independent of this: it answers the prefix question alone, so it can read true for a path the property-path engine went on to deliver whole, unreduced.

Example

The evaluator returns the same two-element array either way; only the engine differs, against the same $-rooted path.

The data output under the property-path enginewhole
["first", "second"]
The data output under the jsonpath engine, same pathunwrapped
"first"

Both report the path as a JSONPath query (is_jsonpath true); only the second reduces it, and only the second counts two matches.

Why

Recorded under OPEN-25.

Rule identifiers are permanent and are never renumbered. Each implementation publishes its own standing against these rules; this specification does not.spec 1.0 · LANG-23 · changed in spec 1.0