Data & APIs

JSON Pointer Explained: Paths, Arrays and Escaped Keys

Learn JSON Pointer syntax, including /0 array indexes, ~0 and ~1 escaping, and the empty root pointer.

Photorealistic editorial photo for Json Pointer Explained
Data & APIs · Practical ideas for your next build

JSON Pointer identifies one value inside a JSON document. It is useful in validation errors, patch operations, and tools that need a stable reference to a nested field. A pointer is a location, not a search expression: it does not provide wildcards or filters.

Read segments from left to right

The empty string identifies the whole document. A slash starts each segment, so /user/name selects name inside user. A pointer consisting of just / selects an object property whose name is the empty string. For arrays, /items/0 selects the first element. Array indexes do not use square brackets and should not have leading zeros.

Escape property names in the right order

Replace tilde with ~0 and slash with ~1 when constructing a segment. When decoding, replace ~1 first and ~0 second. Reversing that decoding order can interpret ~01 incorrectly. A key named a/b is addressed by /a~1b; a key named m~n is addressed by /m~0n. Dots and spaces are ordinary characters in a pointer string.

Separate pointers from URI fragments

A URI fragment representation starts with # and may need percent encoding in addition to pointer escaping. Do not assume a URL-encoded string can be used directly as a plain pointer. A pointer that is syntactically valid can still fail to resolve when a property is absent. Report that condition separately from malformed escape sequences when building an API or validation interface.

Worked example

EXAMPLE
{"a/b":{"m~n":[42]}}
Pointer: /a~1b/m~0n/0
Selected value: 42

Is JSON Pointer the same as JSONPath?

No. JSON Pointer addresses a specific location. JSONPath is a query language with selectors and filtering capabilities.

Reference and further reading

Read the official documentation ↗