API¶
RFC 6901 Parser¶
Implements low-level json pointer parsing. See RFC 6901 Section 4 for the specification that this parser adheres to.
- fast_json_pointer.rfc6901_parser.validate(pointer: str) None¶
Validate that a string is a well formed json pointer.
- Raises:
ParseException: If json pointer is invalid.
>>> validate('') # empty string is fine, means "whole json object" >>> validate('foo') # parts must lead with '/' Traceback (most recent call last): fast_json_pointer.exceptions.ParseException: ... >>> validate('/foo~') # ~ is the escape char, can't be solo Traceback (most recent call last): fast_json_pointer.exceptions.ParseException: ... >>> validate('/~2/foo') # only ~0, ~1 are valid escapes Traceback (most recent call last): fast_json_pointer.exceptions.ParseException: ...
- fast_json_pointer.rfc6901_parser.parse(pointer: str) list[str]¶
Parse a json pointer into a list of unescaped path parts.
- Raises:
ParseException: If json pointer is invalid.
>>> parse('') # empty string is "the whole json object" [] >>> parse('/') # keys can be zero-length strings [''] >>> parse('/ // ') # which can look funky [' ', '', ' '] >>> parse('/foo/m~0n/a~1b') # ~1 escapes /, ~0 escapes ~ ['foo', 'm~n', 'a/b'] >>> parse('/c%d/e^f') # funky symbols are fine too! ['c%d', 'e^f'] >>> parse(r'/i\\j/g|h/k\l') # r-string avoids escaping backslashes ['i\\\\j', 'g|h', 'k\\l']
- fast_json_pointer.rfc6901_parser.unparse(parts: Iterable[str]) str¶
Combine an iterable of unescaped path parts into a json pointer.
>>> unparse([]) '' >>> unparse(['']) '/' >>> unparse([' ', '', ' ']) '/ // ' >>> unparse(['foo', 'm~n', 'a/b']) '/foo/m~0n/a~1b' >>> unparse(['c%d', 'e^f']) '/c%d/e^f' >>> unparse([r'i\\j', 'g|h', r'k\l']) '/i\\\\j/g|h/k\\l'
- fast_json_pointer.rfc6901_parser.escape(part: str) str¶
Escape a path part.
>>> escape("foo") 'foo' >>> escape("m~/0") 'm~0~10'
- fast_json_pointer.rfc6901_parser.unescape(part: str) str¶
Unescape a path part.
>>> unescape("foo") 'foo' >>> unescape("m~0~10") 'm~/0'
Exceptions¶
- exception fast_json_pointer.exceptions.JsonPointerException¶
Generic json pointer failure.
- exception fast_json_pointer.exceptions.ParseException¶
Failure occurred while parsing a json pointer.