Skip to content

Menu

JSONPath Cheat Sheet: RFC 9535 Filters, JSON Pointer and JSON Patch

Checked against JSONPath (RFC 9535) RFC 9535 (Feb 2024), RFC 6901, RFC 6902; run on python-jsonpath 2.3.0, jsonpath-plus 11.3.0 and jq 1.7.1 on 28 November 2026. Each section links to the official docs it was checked against.

This sheet is for developers who query or modify JSON from config, tests or API gateways and keep mixing up the three path syntaxes. It covers JSONPath as standardised in RFC 9535 (February 2024), JSON Pointer (RFC 6901) and JSON Patch (RFC 6902). Every query was run with python-jsonpath 2.3.0 in strict mode, and the differences with jsonpath-plus 11.3.0 and jq 1.7.1 come from my own runs.

When to use what

Use JSONPath when you want to search: every author, every book under 10, all prices anywhere. It returns a list of nodes, possibly empty, and never fails because something is missing. Use JSON Pointer when you already know the exact location and need one value; it is what $ref in JSON Schema and OpenAPI uses and what JSON Patch paths are made of. Use JSON Patch when you need to describe a change to send over HTTP or store in an audit log.

Check which JSONPath dialect your library speaks before you copy an expression. Before RFC 9535 every implementation followed Stefan Goessner's 2007 article differently. The biggest trap in my tests: jsonpath-plus wants filters in parentheses, [?(@.price < 10)], and returned an empty list for the RFC form [[email protected] < 10] without any error. It also returned nothing for [-1], which the RFC defines as the last element.

jq is a different language rather than a JSONPath dialect. Its paths start with . instead of $, and filters use select(). If jq is already in your pipeline, see the jq cheat sheet. To try paths in the browser, use the JSONPath evaluator (it covers names, wildcards, indexes, slices and .., but not filters yet), click through a document with the JSON path finder, and build patches from two versions of a document with the JSON Patch builder.

Examples use the RFC's bookstore document: four books under $.store.book and a red bicycle.

$

Root node; every query starts here

$.store.book[*].author

All four authors via a wildcard over the array

$..author

Descendant segment: every author at any depth (same four names here)

$.store.*

Wildcard on an object: the book array and the bicycle object

$.store..price

Every price under store: four book prices then 399 for the bicycle

$['store']['bicycle']['color']

Bracket notation; needed for keys with spaces, dots or dashes. Returns ["red"]

$.missing

No such member: an empty list, not an error

$..book[2]

Third book (zero-based index)

$..book[-1]

Last book; negative indexes count from the end

$..book[0,1]

Union: first and second book, in the order listed

$..book[:2]

Slice start:end:step, end excluded; same two books as [0,1]

$..book[::-1].title

Negative step walks backwards: titles in reverse order

Our in-browser evaluator doesn't run filters yet, so these were tested in python-jsonpath 2.3.0 only. match() must match the whole string; search() looks for a substring. Both take I-Regexp (RFC 9485) patterns.

Existence test: books that have an isbn member (Moby Dick and The Lord of the Rings)

$..book[[email protected]].title

Negated existence: titles of books without an ISBN

$..book[[email protected] < 10].title

Comparison: Sayings of the Century and Moby Dick

$..book[[email protected] < 10 && @.category == "fiction"].title

Logical AND with a string literal: only Moby Dick

$..book[?length(@.title) > 20].title

length() of a string, array or object; two titles are longer than 20 characters

$..book[?match(@.author, "J.*")].author

Full-string regex match: J. R. R. Tolkien

$..book[?search(@.author, "Tolk")].author

Substring regex search: same result as above

$.store[?count(@.*) > 2]

count() of a nodelist: keeps the book array (4 children), drops the bicycle (2)

/store/book/0/title

One exact value: Sayings of the Century. Array indexes are plain numbers

""

Empty pointer is the whole document; / alone means the key named empty string

/a~1b

~1 encodes / inside a key, so this reads key a/b

/m~0n

~0 encodes ~, so this reads key m~n. Decode ~1 before ~0

/store/book/-

- means past the last element: valid as a Patch add target, an error when reading

#/$defs/address

Pointer in a URI fragment, as used by JSON Schema $ref

A patch is an array of operations applied in order. If any operation fails, the RFC says the whole patch is not successful, and HTTP PATCH is atomic, so nothing should change.

{"op": "add", "path": "/tags/-", "value": "b"}

Append to an array; on an object key that exists, add replaces the value

{"op": "remove", "path": "/tags/0"}

Remove a member or array element; later elements shift down

{"op": "replace", "path": "/v", "value": 2}

Replace an existing value; fails with can't replace nonexistent property if the target is missing

{"op": "move", "from": "/w", "path": "/z"}

Remove from from and add at path

{"op": "copy", "from": "/v", "path": "/w"}

Copy a value to a new location

{"op": "test", "path": "/v", "value": 2}

Assert a value; a failing test aborts the patch, which makes it a cheap optimistic lock

diff two documents

Generate the operations from before and after versions instead of writing them by hand

Each line below was run against the same bookstore file.

jsonpath-plus: $..book[?(@.price < 10)].title

Goessner-style filter with parentheses: works. The RFC form without parentheses returned []

jsonpath-plus: $..book[-1:]

Slice form for the last element; plain [-1] returned [] in 11.3.0

jq: [.store.book[] | select(.price < 10) | .title]

jq equivalent of the price filter: ["Sayings of the Century","Moby Dick"]

jq: [.. | .author? // empty]

jq equivalent of $..author

jq: getpath(["store","bicycle","color"])

jq reads a path given as an array, the closest thing to a JSON Pointer: "red"

Worked example: Find cheap fiction, then patch its price safely

Start with the RFC bookstore document. First find the books to change, and ask for their locations instead of their values:

query: $..book[[email protected] < 10 && @.category == "fiction"]

normalized path: $['store']['book'][2]
value: Moby Dick, price 8.99

RFC 9535 calls $['store']['book'][2] a Normalized Path: one exact node, written in a fixed form. Turn it into a JSON Pointer by dropping $ and joining the keys with slashes: /store/book/2. Then write a patch that only applies if nobody changed the price in the meantime:

[
  { "op": "test", "path": "/store/book/2/price", "value": 8.99 },
  { "op": "replace", "path": "/store/book/2/price", "value": 9.49 }
]

With python-jsonpath 2.3.0 the patch applied and the price became 9.49. When I changed the test value to something else, the library raised JSONPatchTestFailure and the document was left alone. That test line is what makes the patch safe to retry: if another request already changed the price, you get an error instead of overwriting their work. Keep in mind that array indexes in a pointer go stale when items are inserted or removed, so run the query and the patch close together.

Common mistakes

  • Copying a filter like [[email protected] < 10] from the RFC into a library that predates it and getting an empty result.

    Check the library's dialect. jsonpath-plus needs [?(@.price < 10)]; an RFC 9535 library accepts both.

  • Using $..book.length to count items, as old tutorials show.

    RFC 9535 has no script expressions. Count results in your code, or use count() inside a filter.

  • Treating an empty result as proof that a field is absent everywhere.

    An empty nodelist also comes from typos and unsupported syntax. Test the query on a document where you know it should match.

  • Putting a key containing / or ~ straight into a JSON Pointer.

    Escape ~ as ~0 and / as ~1, in that order, when building the pointer.

  • Using add and expecting it to fail if the key exists.

    add on an existing object member replaces it. Put a test operation first if you need to guard the old value.

  • Sending a JSON Patch with Content-Type: application/json.

    RFC 6902 registers application/json-patch+json for patch documents. Send that type so the server knows the body is a list of operations.