- JSONPathEnvironment
- Environment customization
- Class attributes
- filter_caching
- function_extensions
- lexer
- parser
- unicode_escape
- well_typed
- check_well_typedness
- compare
- compile
- findall
- findall_async
- finditer
- finditer_async
- getitem
- getitem_async
- is_truthy
- match
- query
- setup_function_extensions
- validate_function_extension_signature
- JSONPathMatch
- JSONPath
- CompoundJSONPath
- Query
- Projection
- FilterFunction
- ExpressionType
- JSONPointer
- RelativeJSONPointer
- JSONPatch
API Reference
jsonpath.JSONPathEnvironment
JSONPath configuration.
This class contains settings for path tokenization, parsing and resolutionbehavior, plus convenience methods for matching an unparsed path to somedata.
Most applications will want to create a singleJSONPathEnvironment
, orusejsonpath.compile()
,jsonpath.findall()
, etc. from the package-leveldefault environment.
Environment customization
Environment customization is achieved by subclassingJSONPathEnvironment
and overriding class attributes and/or methods. Some of thesecustomizations 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 levelabove the real root node. TYPE: |
filter_context_token | The pattern used to select extra filter contextdata. 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 whenfiltering 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 byindex. Defaults to TYPE: |
min_int_index | The minimum integer allowed when selecting array items byindex. 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 JSONdocument. Defaults to TYPE: |
union_token | The pattern used as the union operator. Defaults to TYPE: |
filter_cachinginstance-attribute
Enable or disable filter expression caching.
function_extensionsinstance-attribute
A list of function extensions available to filters.
unicode_escapeinstance-attribute
Enable or disable decoding of UTF-16 escape sequences found inJSONPath string literals.
well_typedinstance-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 operatorbehavior.
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 | givenoperator, 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 | Ifpath is invalid. |
JSONPathTypeError | If filter functions are given arguments of anunacceptable type. |
findall
findall(path:str,data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->List[object]
Find all objects indata matching the JSONPathpath.
Ifdata is a string or a file-like objects, it will be loadedusingjson.loads()
and the defaultJSONDecoder
.
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 usingthefilter context selector. TYPE: |
RETURNS | DESCRIPTION |
---|---|
List[object] | A list of matched objects. If there are no matches, the list willbe empty. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError | If the path is invalid. |
JSONPathTypeError | If a filter expression attempts to use types inan incompatible way. |
findall_asyncasync
findall_async(path:str,data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->List[object]
An async version offindall()
.
finditer
finditer(path:str,data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->Iterable[JSONPathMatch]
GenerateJSONPathMatch
objects for each match ofpath indata.
Ifdata is a string or a file-like objects, it will be loaded usingjson.loads()
and the defaultJSONDecoder
.
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 usingthefilter 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 inan incompatible way. |
finditer_asyncasync
finditer_async(path:str,data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->AsyncIterable[JSONPathMatch]
An async version offinditer()
.
getitem
Sequence and mapping item getter used throughout JSONPath resolution.
The default implementation ofgetitem
simply callsoperators.getitem()
from Python's standard library. Same asobj[key]
.
PARAMETER | DESCRIPTION |
---|---|
obj | A mapping or sequence that might containkey. TYPE: |
key | A mapping key, sequence index or sequence slice. TYPE: |
is_truthy
Test for truthiness when evaluating JSONPath filter expressions.
In some cases, RFC 9535 requires us to test for existence rather thantruthiness. So the default implementation returnsTrue
for emptycollections andNone
. The specialUNDEFINED
object means thatobj was missing, as opposed to an explicitNone
.
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 aJSONPathMatch
instance for the first object found indata.
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 usingthefilter 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 inan incompatible way. |
query
query(path:str,data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],filter_context:Optional[FilterContextVars]=None,)->Query
Return aQuery
iterator over matches found by applyingpath todata.
Query
objects are iterable.
You can skip and limit results withQuery.skip()
andQuery.limit()
.
Query.tail()
will get the lastn results.
Get values for each match usingQuery.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 usingthefilter 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 inan incompatible way. |
jsonpath.JSONPathMatch
A matched object with a concrete path.
ATTRIBUTE | DESCRIPTION |
---|---|
children | Matched child nodes. This will only be populated afterall 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 thismatch. 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 indata
matching the given JSONPathpath
.
Ifdata
is a string or a file-like objects, it will be loadedusingjson.loads()
and the defaultJSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data | A JSON document or Python object implementing the TYPE: |
filter_context | Arbitrary data made available to filters usingthefilter 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 inan incompatible way. |
findall_asyncasync
findall_async(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->List[object]
An async version offindall()
.
finditer
finditer(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->Iterable[JSONPathMatch]
GenerateJSONPathMatch
objects for each match.
Ifdata
is a string or a file-like objects, it will be loadedusingjson.loads()
and the defaultJSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data | A JSON document or Python object implementing the TYPE: |
filter_context | Arbitrary data made available to filters usingthefilter 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 inan incompatible way. |
finditer_asyncasync
finditer_async(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->AsyncIterable[JSONPathMatch]
An async version offinditer()
.
match
match(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->Union[JSONPathMatch,None]
Return aJSONPathMatch
instance for the first object found indata.
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 usingthefilter 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 inan incompatible way. |
query
query(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->Query
Return aQuery
iterator over matches found by applying this path todata.
PARAMETER | DESCRIPTION |
---|---|
data | A JSON document or Python object implementing the TYPE: |
filter_context | Arbitrary data made available to filters usingthefilter 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 inan incompatible way. |
jsonpath.CompoundJSONPath
MultipleJSONPath
s combined.
findall
findall(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->List[object]
Find all objects indata
matching the given JSONPathpath
.
Ifdata
is a string or a file-like objects, it will be loadedusingjson.loads()
and the defaultJSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data | A JSON document or Python object implementing the TYPE: |
filter_context | Arbitrary data made available to filters usingthefilter context selector. TYPE: |
RETURNS | DESCRIPTION |
---|---|
List[object] | A list of matched objects. If there are no matches, the list willbe empty. |
RAISES | DESCRIPTION |
---|---|
JSONPathSyntaxError | If the path is invalid. |
JSONPathTypeError | If a filter expression attempts to use types inan incompatible way. |
findall_asyncasync
findall_async(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->List[object]
An async version offindall()
.
finditer
finditer(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->Iterable[JSONPathMatch]
GenerateJSONPathMatch
objects for each match.
Ifdata
is a string or a file-like objects, it will be loadedusingjson.loads()
and the defaultJSONDecoder
.
PARAMETER | DESCRIPTION |
---|---|
data | A JSON document or Python object implementing the TYPE: |
filter_context | Arbitrary data made available to filters usingthefilter 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 inan incompatible way. |
finditer_asyncasync
finditer_async(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->AsyncIterable[JSONPathMatch]
An async version offinditer()
.
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 aJSONPathMatch
instance for the first object found indata.
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 usingthefilter 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 inan incompatible way. |
query
query(data:Union[str,IOBase,Sequence[Any],Mapping[str,Any]],*,filter_context:Optional[FilterContextVars]=None)->Query
Return aQuery
iterator over matches found by applying this path todata.
PARAMETER | DESCRIPTION |
---|---|
data | A JSON document or Python object implementing the TYPE: |
filter_context | Arbitrary data made available to filters usingthefilter 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 inan incompatible way. |
jsonpath.Query
A fluent API for managingJSONPathMatch
iterators.
Usually you'll want to usejsonpath.query()
orJSONPathEnvironment.query()
to create instances ofQuery
rather than instantiatingQuery
directly.
PARAMETER | DESCRIPTION |
---|---|
it | A TYPE: |
New in version 1.1.0
drop
Skip up ton matches from the query iterator.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
first
Limit the query iterator to at most the firstn matches.
first()
is an alias forlimit()
.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
first_one
Return the firstJSONPathMatch
orNone
if there were no matches.
head
Limit the query iterator to at most the firstn matches.
head()
is an alias forlimit()
.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
items
Return an iterable of (path, object) tuples, one for each match.
last
Drop up to the lastn matches from the iterator.
last()
is an alias fortail()
.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
last_one
Return the lastJSONPathMatch
orNone
if there were no matches.
limit
Limit the query iterator to at mostn matches.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
one
Return the firstJSONPathMatch
orNone
if there were no matches.
one()
is an alias forfirst_one()
.
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 relativeto each match in this query iterator. TYPE: |
projection | The style of projection used when selecting values. Can beone of TYPE: |
RETURNS | DESCRIPTION |
---|---|
Iterable[object] | An iterable of objects built from selectingexpressions relative toeach match from the current query. |
New in version 1.2.0
skip
Skip up ton matches from the query iterator.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
tail
Drop matches up to the lastn matches from the iterator.
RAISES | DESCRIPTION |
---|---|
ValueError | Ifn < 0. |
take
Return a new query iterating over the nextn matches.
It is safe to continue using this query after calling take.
tee
Returnn independent queries by teeing this query's iterator.
It is not safe to use aQuery
instance after callingtee()
.
jsonpath.Projection
Bases:Enum
Projection style used byQuery.select()
.
FLATclass-attribute
instance-attribute
All selections are appended to a new array/list, without arrays and objectson the path to the selected value.
RELATIVEclass-attribute
instance-attribute
The default projection. Selections include parent arrays and objects relativeto the JSONPathMatch.
jsonpath.function_extensions.FilterFunction
Bases:ABC
Base class for typed function extensions.
arg_typesabstractmethod
property
Argument types expected by the filter function.
return_typeabstractmethod
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. Ifgiven, it is assumed that the parts have already been parsed by theJSONPath parser. TYPE: |
unicode_escape | If TYPE: |
uri_decode | If TYPE: |
ATTRIBUTE | DESCRIPTION |
---|---|
keys_selector | The non-standard token used to target a mappingkey or name. TYPE: |
max_int_index | The maximum integer allowed when resolving arrayitems by index. Defaults to TYPE: |
min_int_index | The minimum integer allowed when resolving arrayitems by index. Defaults to TYPE: |
__truediv__
Join this pointer withother.
other is expected to be a JSON Pointer string, possibly without aleading slash. Ifother does have a leading slash, the previouspointer is ignored and a new JSONPath is returned fromother.
other should not be a "Relative JSON Pointer".
exists
ReturnTrue if this pointer can be resolved againstdata.
Note thatJSONPointer.resolve()
can return legitimate falsy valuesthat form part of the target JSON document. This method will returnTrue
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 againstdata, orFalseotherwise. |
New in version 0.9.0
from_matchclassmethod
Return a JSON Pointer for the path from a JSONPathMatch instance.
from_partsclassmethod
from_parts(parts:Iterable[Union[int,str]],*,unicode_escape:bool=True,uri_decode:bool=False)->JSONPointer
Build a JSON Pointer fromparts.
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
ReturnTrue if this pointer points to a child ofother.
join
Join this pointer withparts.
Each part is expected to be a JSON Pointer string, possibly without aleading slash. If a part does have a leading slash, the previouspointer is ignored and a newJSONPointer
is created, and processing ofremaining parts continues.
parent
Return this pointer's parent, as a newJSONPointer
.
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 againstdata.
PARAMETER | DESCRIPTION |
---|---|
data | The target JSON "document" or equivalent Python objects. TYPE: |
default | A default value to return if the pointer can't be resolvedagainst the given data. TYPE: |
RETURNS | DESCRIPTION |
---|---|
object | The object indata pointed to by this pointer. |
RAISES | DESCRIPTION |
---|---|
JSONPointerIndexError | When attempting to access a sequence byan out of range index, unless a default is given. |
JSONPointerKeyError | If any mapping object along the path does notcontain a specified key, unless a default is given. |
JSONPointerTypeError | When attempting to resolve a non-index stringpath 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 againstdata, 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 byan out of range index, unless using the special |
JSONPointerKeyError | If any mapping object along the path does notcontain a specified key, unless it is the last part of thepointer. |
JSONPointerTypeError | When attempting to resolve a non-index stringpath 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
Return a new JSONPointer relative topointer.
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 | Ifops is given and any of the provided operationsis malformed. |
add
Append anadd operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
value | The object to add. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |
addap
Append anaddap operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
value | The object to add. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |
addne
Append anaddne operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
value | The object to add. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |
apply
Apply all operations from this patch todata.
Ifdata is a string or file-like object, it will be loaded withjson.loads. Otherwisedata should be a JSON-like data structure andwill be modified in place.
When modifyingdata in place, we return modified data too. This isto allow for replacingdata's root element, which is allowed by somepatch 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 atest operation does not pass. |
copy
Append acopy operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
from_ | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
path | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |
move
Append amove operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
from_ | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
path | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |
remove
Append aremove operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path | A string representation of a JSON Pointer, or one that hasalready been parsed. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |
replace
Append areplace operation to this patch.
PARAMETER | DESCRIPTION |
---|---|
path | A string representation of a JSON Pointer, or one that hasalready 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 hasalready been parsed. TYPE: |
value | The object to test. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | This |