Pointer Backends¶
This module contains the pointer backend protocol and related backend-level
utilities used by JSONPointer.
DEFAULT_POINTER_CLS
¶
Default JSON Pointer backend powered by jsonpointer.JsonPointer.
This implementation parses RFC 6901 pointer strings, exposes unescaped parts, reconstructs canonical pointers from parts, and resolves pointers against JSON documents.
Source code in jsonpatchx/backend.py
parts
property
¶
Return the pointer's unescaped RFC 6901 reference tokens.
Returns:
| Type | Description |
|---|---|
Sequence[str]
|
The pointer's unescaped reference tokens. |
from_parts(parts)
classmethod
¶
Build a canonical RFC 6901 pointer from unescaped reference tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
Iterable[str]
|
Unescaped RFC 6901 reference tokens. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A canonical RFC 6901 pointer for those tokens. |
Source code in jsonpatchx/backend.py
DEFAULT_SELECTOR_CLS
¶
Default JSONPath selector backend powered by python-jsonpath.
This implementation compiles JSONPath expressions with the shared strict environment and yields exact pointer locations for each match.
Disclaimer
This backend follows RFC 9535 path syntax and semantics, except on
Python 3.14 and later where regex-related behavior falls back to
Python's built-in re module because the upstream iregexp-check
dependency is not yet compatible with free-threaded Python.
Source code in jsonpatchx/backend.py
pointers(doc)
¶
Yield canonical RFC 6901 pointers for each matched location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
JSONValue
|
JSON document to evaluate against. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[DEFAULT_POINTER_CLS]
|
An iterable of canonical RFC 6901 pointers for each match. |
Source code in jsonpatchx/backend.py
PointerBackend
¶
Bases: Protocol
Protocol for pointer implementations used by JSONPointer.
A pointer backend parses a pointer string, exposes unescaped parts,
reconstructs itself from those parts, resolves against a JSON document, and
round-trips through str().
Required Invariants
str(type(ptr)(str(ptr))) == str(ptr)str(type(ptr).from_parts(ptr.parts)) == str(ptr)
Backends define their own syntax and root representation. Higher-level JsonPatchX APIs normalize backend-raised errors, and backend instances should be safe to reuse across calls.
Source code in jsonpatchx/backend.py
parts
abstractmethod
property
¶
Return unescaped pointer parts.
Returns:
| Type | Description |
|---|---|
Sequence[str]
|
The pointer's unescaped parts in traversal order. |
from_parts(parts)
abstractmethod
classmethod
¶
Build a pointer from unescaped parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
Iterable[str]
|
Unescaped pointer parts in traversal order. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A pointer equivalent to those parts. |
Source code in jsonpatchx/backend.py
SelectorBackend
¶
Bases: Protocol
Protocol for custom query selector backends.
A selector backend is the query analogue of PointerBackend: it parses a
selector string and can iterate exact matched pointers against a JSON
document.
Required invariants
str(type(sel)(str(sel))) == str(sel)
Source code in jsonpatchx/backend.py
pointers(doc)
abstractmethod
¶
Yield exact matched pointers against a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
JSONValue
|
JSON document to evaluate against. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[PointerBackend]
|
An iterable of exact matched pointers. |
Source code in jsonpatchx/backend.py
TargetState
¶
Bases: Enum
Resolution state for applying a pointer-like operation to a document.
Values
MISSING: The root pointer targets a missing document.ROOT: The pointer targets the document root.PARENT_NOT_FOUND: A parent pointer segment could not be resolved.PARENT_NOT_CONTAINER: The parent resolved, but is neither an object nor an array.OBJECT_KEY_MISSING: The parent is an object, and the final key is not present.ARRAY_KEY_INVALID: The parent is an array, and the final token is not a valid array index or append token.ARRAY_INDEX_OUT_OF_RANGE: The parent is an array, and the numeric index is outside the accepted range.ARRAY_INDEX_AT_END: The parent is an array, and the numeric index is exactlylen(array).ARRAY_INDEX_APPEND: The parent is an array, and the final token is"-".VALUE_PRESENT: The pointer names an existing value.VALUE_PRESENT_AT_NEGATIVE_ARRAY_INDEX: The pointer names an existing array element through a negative index.
Source code in jsonpatchx/backend.py
classify_state(ptr, doc)
¶
Classify how a pointer relates to a document without mutating it.
Useful for determining the applicability of an operation before attempting to apply it, and for generating informative error messages on failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ptr
|
PointerBackend
|
Pointer to classify. |
required |
doc
|
JSONValue
|
Document to classify the pointer against. |
required |
Returns:
| Type | Description |
|---|---|
TargetState
|
The resolution state that best describes how |