Skip to content

Pointers

pointers

Bundle-local JSON Pointer validation.

Bundle-local references use RFC 6901 JSON Pointer syntax: #/ marks the bundle root, ~0 escapes ~, and ~1 escapes / within mapping keys.

For example: * #/objects/item starts at the bundle root and selects item. * #/objects/a~1b selects the key a/b. * #/objects/a~0b selects the key a~b.

Functions:

decode_json_pointer_parts

decode_json_pointer_parts(pointer: str) -> list[str]

Decode and validate the syntax of a local JSON Pointer.

Parameters:

Name Type Description Default
pointer str

Bundle-local JSON Pointer beginning with #/.

required

Returns:

Type Description
list[str]

Decoded JSON Pointer path segments.

Raises:

Type Description
BundlePointerResolutionError

If a path segment contains an invalid ~ escape.

parse_json_pointer_array_index

parse_json_pointer_array_index(part: str) -> int

Parse a valid JSON Pointer array index.

Parameters:

Name Type Description Default
part str

Decoded JSON Pointer path segment addressing an array element.

required

Returns:

Type Description
int

The non-negative array index.

Raises:

Type Description
BundlePointerResolutionError

If part is not 0 or a non-zero digit followed by digits.

validate_and_expand_bundle_references

validate_and_expand_bundle_references(document: Mapping[str, Any]) -> Mapping[str, Any]

Validate local pointers and build one expanded document for validation.

Parameters:

Name Type Description Default
document Mapping[str, Any]

Decoded JSON bundle document to inspect.

required

Returns:

Type Description
Mapping[str, Any]

Document with resolvable local pointers expanded.

Raises:

Type Description
BundleReferenceError

If one or more local pointers cannot resolve.