Skip to content
yutils
Example

Input (JSON + JSONPath)

JSON:
{ "store": { "book": [ { "title": "A", "price": 10 }, { "title": "B", "price": 25 } ] } }

JSONPath: $.store.book[?(@.price > 15)].title

Output

[ "B" ]

Note

JSONPath is an XPath-like query syntax for JSON. `$` is root, `..` is recursive descent, `[?(...)]` is a filter.

Usage / FAQ

When to use

  • Extract specific fields from a large JSON response
  • Filter items by price, date, or other conditions
  • Test path expressions quickly when `jq` is not handy
  • Pluck meaningful data from an API doc's sample JSON
  • Inspect a fragment of a GraphQL response visually

FAQ

Q.Is JSONPath the same as jq?
A.No. JSONPath is XPath-inspired path syntax; jq is a functional DSL. JSONPath is shorter for plain extraction; jq is stronger for transformation and aggregation.
Q.When do I use `..` (recursive descent)?
A.When you don't know the depth. E.g. `$..price` collects every `price` key regardless of nesting level.
Q.Is the result always an array?
A.Yes. JSONPath returns zero or more matches, so the result is always an array. Pick the first element (`[0]`) if you need a single value.
Fun facts
  • JSONPath was proposed in 2007 by Stefan Gössner as an attempt to bring XPath-style querying to JSON. `$` (root) / `.` (child) / `[*]` (wildcard) / `..` (recursive descent) — the same conventions XPath uses, applied to a JSON tree.

    Gössner — JSONPath (2007)
  • JSONPath spent 17 years as a 'standard' that every library implemented slightly differently — until **RFC 9535 (2024)** finally made it an official IETF standard. Filter expressions like `$..book[?@.price < 10]` are now part of the spec, so cross-library compatibility is guaranteed.

    RFC 9535 (2024)
  • JSONPath's cousins — JMESPath, jq's query language, and others — appeared in a similar window. AWS CLI made JMESPath part of every shell user's vocabulary, and `jq` ended up in everyone's aliases. 'Extract a value from a JSON tree' became its own shell-tool category.

    Wikipedia — JSONPath