Learn JSONPath
RFC 9535 — XPath-style queries that return a list of every match.
Basics
- Root & child segments Every JSONPath starts at the root $. Add child segments with dots (.name) or brackets (['name']) — brackets…
- Array indexes [n] picks one element (zero-based). A negative index counts from the end.
- 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
- Wildcards [*] or .* selects every element of an array, or every member of an object.
- Slices [start:end:step] selects a range. end is exclusive, every part is optional, negative values count from the…
- Unions Put several selectors in one bracket, separated by commas, to collect them together — in the order written.
- Descendants: .. .. searches the whole subtree, at any depth, instead of one fixed level.
Filters
- Comparisons [?condition] keeps the children for which the condition is true. Inside it, @ stands for the child being…
- Combining conditions && (and), || (or) and ! (not) combine tests. Use parentheses to group.
- Existence tests A bare path inside a filter tests whether it exists — no comparison needed. Put ! in front to test that it…
- 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…
- Functions RFC 9535 defines length(), count(), match(), search() and value() for use inside filters.
Gotchas
- Filter, then index Selectors chain: each one applies to the children of what the previous one matched. So [?…][0] does not mean…