Learn JSONPath

RFC 9535 — XPath-style queries that return a list of every match.

The JSONPath cheat sheet

Basics

  1. Root & child segments Every JSONPath starts at the root $. Add child segments with dots (.name) or brackets (['name']) — brackets…
  2. Array indexes [n] picks one element (zero-based). A negative index counts from the end.
  3. Results are lists JSONPath always returns a list of matches: zero, one or many. A path that matches nothing is not an error —…

Selecting many

  1. Wildcards [*] or .* selects every element of an array, or every member of an object.
  2. Slices [start:end:step] selects a range. end is exclusive, every part is optional, negative values count from the…
  3. Unions Put several selectors in one bracket, separated by commas, to collect them together — in the order written.
  4. Descendants: .. .. searches the whole subtree, at any depth, instead of one fixed level.

Filters

  1. Comparisons [?condition] keeps the children for which the condition is true. Inside it, @ stands for the child being…
  2. Combining conditions && (and), || (or) and ! (not) combine tests. Use parentheses to group.
  3. Existence tests A bare path inside a filter tests whether it exists — no comparison needed. Put ! in front to test that it…
  4. Comparing with the rest of the document Inside a filter, $ still means the document root, so an element can be compared with any other value in the…
  5. Functions RFC 9535 defines length(), count(), match(), search() and value() for use inside filters.

Gotchas

  1. Filter, then index Selectors chain: each one applies to the children of what the previous one matched. So [?…][0] does not mean…

About jsonquery

Query, format and learn JSON with jq, JSONPath, JMESPath and JSON Pointer. It is the engine of the desktop app, run in your browser.

Engine
The desktop app’s, compiled to WebAssembly
Licence
MIT (the engine and the app)
Source
GitHub
Contact
The contact form (private)
Public issues
GitHub
Legal
Privacy policy

Known limitations: a file over 10 MB opens read-only and one over 512 MB does not open here; the desktop app has no such limit.