API Reference
jsonpath.JSONPathEnvironment
JSONPath configuration.
This class contains settings for path tokenization, parsing and resolution behavior, plus convenience methods for matching an unparsed path to some data.
Most applications will want to create a single JSONPathEnvironment
, or
use jsonpath.compile()
, jsonpath.findall()
, etc. from the package-level
default environment.
Environment customization
Environment customization is achieved by subclassing JSONPathEnvironment
and overriding class attributes and/or methods. Some of these
customizations include:
- Changing the root (
$
), self (@
) or filter context (_
) token with class attributesroot_token
,self_token
andfilter_context_token
. - Registering a custom lexer or parser with the class attributes
lexer_class
orparser_class
.lexer_class
must be a subclass ofLexer
andparser_class
must be a subclass ofParser
. - Setup built-in function extensions by overriding
setup_function_extensions()
- Hook in to mapping and sequence item getting by overriding
getitem()
. - Change filter comparison operator behavior by overriding
compare()
.
PARAMETER | DESCRIPTION |
---|---|
filter_caching
|
If
TYPE:
|
unicode_escape
|
If
TYPE:
|
well_typed
|
Control well-typedness checks on filter function expressions.
If New in version 0.10.0
TYPE:
|
Class attributes
ATTRIBUTE | DESCRIPTION |
---|---|
fake_root_token |
The pattern used to select a "fake" root node, one level above the real root node.
TYPE:
|
filter_context_token |
The pattern used to select extra filter context
data. Defaults to
TYPE:
|
intersection_token |
The pattern used as the intersection operator.
Defaults to
TYPE:
|
key_token |
The pattern used to identify the current key or index when
filtering a, mapping or sequence. Defaults to
TYPE:
|
keys_selector_token |
The pattern used as the "keys" selector. Defaults to
TYPE:
|
lexer_class |
The lexer to use when tokenizing path strings.
TYPE:
|
max_int_index |
The maximum integer allowed when selecting array items by
index. Defaults to
TYPE:
|
min_int_index |
The minimum integer allowed when selecting array items by
index. Defaults to
TYPE:
|
parser_class |
The parser to use when parsing tokens from the lexer.
TYPE:
|
root_token |
The pattern used to select the root node in a JSON document.
Defaults to
TYPE:
|
self_token |
The pattern used to select the current node in a JSON
document. Defaults to
TYPE:
|
union_token |
The pattern used as the union operator. Defaults to
TYPE:
|
filter_caching
instance-attribute
Enable or disable filter expression caching.
function_extensions
instance-attribute
A list of function extensions available to filters.
parser
instance-attribute
The parser bound to this environment.
unicode_escape
instance-attribute
Enable or disable decoding of UTF-16 escape sequences found in JSONPath string literals.
well_typed
instance-attribute
Control well-typedness checks on filter function expressions.
check_well_typedness
Check the well-typedness of a function's arguments at compile-time.
compare
Object comparison within JSONPath filters.
Override this to customize filter expression comparison operator behavior.
PARAMETER | DESCRIPTION |
---|---|
left
|
The left hand side of the comparison expression.
TYPE:
|
operator
|
The comparison expression's operator.
TYPE:
|
right
|
The right hand side of the comparison expression.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
bool
|
given operator, is truthy. |
compile
Prepare a path string ready for repeated matching against different data.
PARAMETER | DESCRIPTION |
---|---|
path
|
A JSONPath as a string.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[JSONPath, CompoundJSONPath]
|
A |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If path is invalid. |
JSONPathTypeError
|
If filter functions are given arguments of an unacceptable type. |
findall
findall(
path: str,
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> List[object]
Find all objects in data matching the JSONPath path.
If data is a string or a file-like objects, it will be loaded
using json.loads()
and the default JSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
path
|
The JSONPath as a string.
TYPE:
|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[object]
|
A list of matched objects. If there are no matches, the list will be empty. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
findall_async
async
findall_async(
path: str,
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> List[object]
An async version of findall()
.
finditer
finditer(
path: str,
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Iterable[JSONPathMatch]
Generate JSONPathMatch
objects for each match of path in data.
If data is a string or a file-like objects, it will be loaded using
json.loads()
and the default JSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
path
|
The JSONPath as a string.
TYPE:
|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[JSONPathMatch]
|
An iterator yielding |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
finditer_async
async
finditer_async(
path: str,
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> AsyncIterable[JSONPathMatch]
An async version of finditer()
.
getitem
Sequence and mapping item getter used throughout JSONPath resolution.
The default implementation of getitem
simply calls operators.getitem()
from Python's standard library. Same as obj[key]
.
PARAMETER | DESCRIPTION |
---|---|
obj
|
A mapping or sequence that might contain key.
TYPE:
|
key
|
A mapping key, sequence index or sequence slice.
TYPE:
|
getitem_async
async
An async sequence and mapping item getter.
is_truthy
Test for truthiness when evaluating JSONPath filter expressions.
In some cases, RFC 9535 requires us to test for existence rather than
truthiness. So the default implementation returns True
for empty
collections and None
. The special UNDEFINED
object means that
obj was missing, as opposed to an explicit None
.
PARAMETER | DESCRIPTION |
---|---|
obj
|
Any object.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
match
match(
path: str,
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Union[JSONPathMatch, None]
Return a JSONPathMatch
instance for the first object found in data.
None
is returned if there are no matches.
PARAMETER | DESCRIPTION |
---|---|
path
|
The JSONPath as a string.
TYPE:
|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[JSONPathMatch, None]
|
A |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
query
query(
path: str,
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
filter_context: Optional[FilterContextVars] = None,
) -> Query
Return a Query
iterator over matches found by applying path to data.
Query
objects are iterable.
You can skip and limit results with Query.skip()
and Query.limit()
.
Query.tail()
will get the last n results.
Get values for each match using Query.values()
.
PARAMETER | DESCRIPTION |
---|---|
path
|
The JSONPath as a string.
TYPE:
|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Query
|
A query iterator. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
jsonpath.JSONPathMatch
A matched object with a concrete path.
ATTRIBUTE | DESCRIPTION |
---|---|
children |
Matched child nodes. This will only be populated after
all children have been visited, usually by using
TYPE:
|
obj |
The matched object.
TYPE:
|
parent |
The immediate parent to this match in the JSON document.
If this is the root node, parent will be
TYPE:
|
path |
The canonical string representation of the path to this match.
TYPE:
|
parts |
The keys, indices and/or slices that make up the path to this match.
TYPE:
|
root |
A reference to the root node in the JSON document.
TYPE:
|
jsonpath.JSONPath
A compiled JSONPath ready to be applied to a JSON string or Python object.
PARAMETER | DESCRIPTION |
---|---|
env
|
The
TYPE:
|
selectors
|
An iterable of
TYPE:
|
fake_root
|
Indicates if target JSON values should be wrapped in a single- element array, so as to make the target root value selectable.
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
env |
The
|
selectors |
The
|
findall
findall(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> List[object]
Find all objects in data
matching the given JSONPath path
.
If data
is a string or a file-like objects, it will be loaded
using json.loads()
and the default JSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[object]
|
A list of matched objects. If there are no matches, the list will |
List[object]
|
be empty. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
findall_async
async
findall_async(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> List[object]
An async version of findall()
.
finditer
finditer(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Iterable[JSONPathMatch]
Generate JSONPathMatch
objects for each match.
If data
is a string or a file-like objects, it will be loaded
using json.loads()
and the default JSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[JSONPathMatch]
|
An iterator yielding |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
finditer_async
async
finditer_async(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> AsyncIterable[JSONPathMatch]
An async version of finditer()
.
match
match(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Union[JSONPathMatch, None]
Return a JSONPathMatch
instance for the first object found in data.
None
is returned if there are no matches.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[JSONPathMatch, None]
|
A |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
query
query(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Query
Return a Query
iterator over matches found by applying this path to data.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Query
|
A query iterator. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
jsonpath.CompoundJSONPath
Multiple JSONPath
s combined.
findall
findall(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> List[object]
Find all objects in data
matching the given JSONPath path
.
If data
is a string or a file-like objects, it will be loaded
using json.loads()
and the default JSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[object]
|
A list of matched objects. If there are no matches, the list will be empty. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
findall_async
async
findall_async(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> List[object]
An async version of findall()
.
finditer
finditer(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Iterable[JSONPathMatch]
Generate JSONPathMatch
objects for each match.
If data
is a string or a file-like objects, it will be loaded
using json.loads()
and the default JSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[JSONPathMatch]
|
An iterator yielding |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
finditer_async
async
finditer_async(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> AsyncIterable[JSONPathMatch]
An async version of finditer()
.
intersection
Intersection of this path and another path.
match
match(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Union[JSONPathMatch, None]
Return a JSONPathMatch
instance for the first object found in data.
None
is returned if there are no matches.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[JSONPathMatch, None]
|
A |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
query
query(
data: Union[
str, IOBase, Sequence[Any], Mapping[str, Any]
],
*,
filter_context: Optional[FilterContextVars] = None
) -> Query
Return a Query
iterator over matches found by applying this path to data.
PARAMETER | DESCRIPTION |
---|---|
data
|
A JSON document or Python object implementing the
TYPE:
|
filter_context
|
Arbitrary data made available to filters using the filter context selector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Query
|
A query iterator. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError
|
If the path is invalid. |
JSONPathTypeError
|
If a filter expression attempts to use types in an incompatible way. |
jsonpath.Query
A fluent API for managing JSONPathMatch
iterators.
Usually you'll want to use jsonpath.query()
or JSONPathEnvironment.query()
to create instances of Query
rather than instantiating Query
directly.
PARAMETER | DESCRIPTION |
---|---|
it
|
A
TYPE:
|
New in version 1.1.0
drop
Skip up to n matches from the query iterator.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
first
Limit the query iterator to at most the first n matches.
first()
is an alias for limit()
.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
first_one
Return the first JSONPathMatch
or None
if there were no matches.
head
Limit the query iterator to at most the first n matches.
head()
is an alias for limit()
.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
items
Return an iterable of (path, object) tuples, one for each match.
last
Drop up to the last n matches from the iterator.
last()
is an alias for tail()
.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
last_one
Return the last JSONPathMatch
or None
if there were no matches.
limit
Limit the query iterator to at most n matches.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
one
Return the first JSONPathMatch
or None
if there were no matches.
one()
is an alias for first_one()
.
pointers
Return an iterable of JSONPointers, one for each match.
select
select(
*expressions: Union[str, JSONPath, CompoundJSONPath],
projection: Projection = Projection.RELATIVE
) -> Iterable[object]
Query projection using relative JSONPaths.
PARAMETER | DESCRIPTION |
---|---|
expressions
|
One or more JSONPath query expressions to select relative to each match in this query iterator.
TYPE:
|
projection
|
The style of projection used when selecting values. Can be
one of
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[object]
|
An iterable of objects built from selecting expressions relative to each match from the current query. |
New in version 1.2.0
skip
Skip up to n matches from the query iterator.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
tail
Drop matches up to the last n matches from the iterator.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If n < 0. |
take
Return a new query iterating over the next n matches.
It is safe to continue using this query after calling take.
tee
Return n independent queries by teeing this query's iterator.
It is not safe to use a Query
instance after calling tee()
.
jsonpath.Projection
Bases: Enum
Projection style used by Query.select()
.
FLAT
class-attribute
instance-attribute
All selections are appended to a new array/list, without arrays and objects on the path to the selected value.
RELATIVE
class-attribute
instance-attribute
The default projection. Selections include parent arrays and objects relative to the JSONPathMatch.
jsonpath.function_extensions.FilterFunction
Bases: ABC
Base class for typed function extensions.
arg_types
abstractmethod
property
Argument types expected by the filter function.
return_type
abstractmethod
property
The type of the value returned by the filter function.
jsonpath.function_extensions.ExpressionType
Bases: Enum
The type of a filter function argument or return value.
jsonpath.JSONPointer
Identify a single, specific value in JSON-like data, as per RFC 6901.
PARAMETER | DESCRIPTION |
---|---|
pointer
|
A string representation of a JSON Pointer.
TYPE:
|
parts
|
The keys, indices and/or slices that make up a JSON Pointer. If
given, it is assumed that the parts have already been parsed by the
JSONPath parser.
TYPE:
|
unicode_escape
|
If
TYPE:
|
uri_decode
|
If
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
keys_selector |
The non-standard token used to target a mapping key or name.
TYPE:
|
max_int_index |
The maximum integer allowed when resolving array
items by index. Defaults to
TYPE:
|
min_int_index |
The minimum integer allowed when resolving array
items by index. Defaults to
TYPE:
|
__truediv__
Join this pointer with other.
other is expected to be a JSON Pointer string, possibly without a leading slash. If other does have a leading slash, the previous pointer is ignored and a new JSONPath is returned from other.
other should not be a "Relative JSON Pointer".
exists
Return True if this pointer can be resolved against data.
Note that JSONPointer.resolve()
can return legitimate falsy values
that form part of the target JSON document. This method will return
True
if a falsy value is found.
PARAMETER | DESCRIPTION |
---|---|
data
|
The target JSON "document" or equivalent Python objects.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if this pointer can be resolved against data, or False otherwise. |
New in version 0.9.0
from_match
classmethod
Return a JSON Pointer for the path from a JSONPathMatch instance.
from_parts
classmethod
from_parts(
parts: Iterable[Union[int, str]],
*,
unicode_escape: bool = True,
uri_decode: bool = False
) -> JSONPointer
Build a JSON Pointer from parts.
PARAMETER | DESCRIPTION |
---|---|
parts
|
The keys, indices and/or slices that make up a JSONPointer.
TYPE:
|
unicode_escape
|
If
TYPE:
|
uri_decode
|
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
JSONPointer
|
A new |
is_relative_to
Return True if this pointer points to a child of other.
join
Join this pointer with parts.
Each part is expected to be a JSON Pointer string, possibly without a
leading slash. If a part does have a leading slash, the previous
pointer is ignored and a new JSONPointer
is created, and processing of
remaining parts continues.
parent
Return this pointer's parent, as a new JSONPointer
.
If this pointer points to the document root, self is returned.
New in version 0.9.0
resolve
resolve(
data: Union[
str, IOBase, Sequence[object], Mapping[str, object]
],
*,
default: object = UNDEFINED
) -> object
Resolve this pointer against data.
PARAMETER | DESCRIPTION |
---|---|
data
|
The target JSON "document" or equivalent Python objects.
TYPE:
|
default
|
A default value to return if the pointer can't be resolved against the given data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
object
|
The object in data pointed to by this pointer. |
RAISES | DESCRIPTION |
---|---|
JSONPointerIndexError
|
When attempting to access a sequence by an out of range index, unless a default is given. |
JSONPointerKeyError
|
If any mapping object along the path does not contain a specified key, unless a default is given. |
JSONPointerTypeError
|
When attempting to resolve a non-index string path part against a sequence, unless a default is given. |
resolve_parent
resolve_parent(
data: Union[
str, IOBase, Sequence[object], Mapping[str, object]
]
) -> Tuple[
Union[Sequence[object], Mapping[str, object], None],
object,
]
Resolve this pointer against data, return the object and its parent.
PARAMETER | DESCRIPTION |
---|---|
data
|
The target JSON "document" or equivalent Python objects.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Union[Sequence[object], Mapping[str, object], None], object]
|
A |
RAISES | DESCRIPTION |
---|---|
JSONPointerIndexError
|
When attempting to access a sequence by
an out of range index, unless using the special |
JSONPointerKeyError
|
If any mapping object along the path does not contain a specified key, unless it is the last part of the pointer. |
JSONPointerTypeError
|
When attempting to resolve a non-index string path part against a sequence. |
to
to(
rel: Union[RelativeJSONPointer, str],
*,
unicode_escape: bool = True,
uri_decode: bool = False
) -> JSONPointer
Return a new pointer relative to this pointer.
PARAMETER | DESCRIPTION |
---|---|
rel
|
A
TYPE:
|
unicode_escape
|
If
TYPE:
|
uri_decode
|
If
TYPE:
|
See https://www.ietf.org/id/draft-hha-relative-json-pointer-00.html
jsonpath.RelativeJSONPointer
A Relative JSON Pointer.
See https://www.ietf.org/id/draft-hha-relative-json-pointer-00.html
PARAMETER | DESCRIPTION |
---|---|
rel
|
A string following Relative JSON Pointer syntax.
TYPE:
|
unicode_escape
|
If
TYPE:
|
uri_decode
|
If
TYPE:
|
to
to(
pointer: Union[JSONPointer, str],
*,
unicode_escape: bool = True,
uri_decode: bool = False
) -> JSONPointer
Return a new JSONPointer relative to pointer.
PARAMETER | DESCRIPTION |
---|---|
pointer
|
A
TYPE:
|
unicode_escape
|
If
TYPE:
|
uri_decode
|
If
TYPE:
|
jsonpath.JSONPatch
Modify JSON-like data with JSON Patch.
RFC 6902 defines operations to manipulate a JSON document. JSONPatch
supports parsing and applying standard JSON Patch formatted operations,
and provides a Python builder API following the same semantics as RFC 6902.
PARAMETER | DESCRIPTION |
---|---|
ops
|
A JSON Patch formatted document or equivalent Python objects.
TYPE:
|
unicode_escape
|
If
TYPE:
|
uri_decode
|
If
TYPE:
|
RAISES | DESCRIPTION |
---|---|
JSONPatchError
|
If ops is given and any of the provided operations is malformed. |
add
Append an add operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
value
|
The object to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
addap
Append an addap operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
value
|
The object to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
addne
Append an addne operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
value
|
The object to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
apply
apply(
data: Union[
str,
IOBase,
MutableSequence[object],
MutableMapping[str, object],
]
) -> object
Apply all operations from this patch to data.
If data is a string or file-like object, it will be loaded with json.loads. Otherwise data should be a JSON-like data structure and will be modified in place.
When modifying data in place, we return modified data too. This is to allow for replacing data's root element, which is allowed by some patch operations.
PARAMETER | DESCRIPTION |
---|---|
data
|
The target JSON "document" or equivalent Python objects.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
object
|
Modified input data. |
RAISES | DESCRIPTION |
---|---|
JSONPatchError
|
When a patch operation fails. |
JSONPatchTestFailure
|
When a test operation does not pass.
|
asdicts
Return a list of this patch's operations as dictionaries.
copy
Append a copy operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
from_
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
move
Append a move operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
from_
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
remove
Append a remove operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
replace
Append a replace operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
value
|
The object to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |
test
Append a test operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path
|
A string representation of a JSON Pointer, or one that has already been parsed.
TYPE:
|
value
|
The object to test.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This |