Encrypt Online
Theme

Data Formats & Debugging

JSONPath vs JSON Pointer for Selection and Addressing

Understand when you need a query language like JSONPath and when you need an exact address like JSON Pointer.

Encrypt Online Editorial Team3 min read
Encrypt Online guide cover on a apricot background with the headline "JSONPath vs JSON Pointer". JSON braces contain a small query lens for selecting values. JSON braces enclose one sparse stepped path terminating at a single filled point. It represents following property and array-index steps to one exact value in the document. It contains no mouse cursor or search lens.

JSONPath and JSON Pointer look related because both are strings that “point into JSON.” They solve different jobs. Confusing them is why queries return nothing or patches target impossible paths.

JSONPath selects matching values; JSON Pointer names one exact location.

In brief

What it is: JSONPath is a query language for selecting JSON values, while JSON Pointer is an exact path syntax for one specific location in a JSON document.

Why it matters: Using the right syntax for the right job makes querying, patching, and validation much easier to reason about.

Worth knowing: Use JSONPath to select possible matches and JSON Pointer when an operation requires one exact address.

Selection vs addressing

JSONPath is for asking questions like “which prices under this tree are greater than 10?” JSON Pointer is for saying “the value at this exact path.” Those are fundamentally different intentions. The first is query-like and can yield many results. The second is address-like and should resolve to at most one location.

Once you frame them that way, the syntax differences stop feeling arbitrary.

Exact updates use JSON Pointer

JSON Patch needs one exact target because it mutates a document. JSON Pointer supplies that address, while JSONPath is designed to return matching values. Choosing between them starts with the workflow question: selection or exact addressing.

  • Use JSONPath to find matching values.
  • Use JSON Pointer to name one exact location.
  • Use JSON Pointer in patch operations and exact structural references.

A cleaner tool split

JSONPath and JSON Pointer should stay separate in your mental model. They solve related but different lookup problems, and combining them too casually hides important failure modes.

See it in a small example

Notice: Operations that update data usually need the exact address supplied by JSON Pointer.

Text
JSONPath -> find all matching values
JSON Pointer -> address one exact value

What to verify

  • Ask whether you need many matches or one exact target.
  • Choose JSON Pointer when the next step mutates or validates one location.
  • Choose JSONPath when you are extracting or filtering values.

Common questions

Can JSONPath replace JSON Pointer?

JSONPath is a selection language, while JSON Pointer supplies the exact addresses used by workflows such as JSON Patch.

Can JSON Pointer return many values?

It resolves to at most one location.

References