Movatterモバイル変換


[0]ホーム

URL:


Skip to content

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 subclassingJSONPathEnvironmentand overriding class attributes and/or methods. Some of thesecustomizations include:

PARAMETERDESCRIPTION
filter_caching

IfTrue, filter expressions will be cachedwhere possible.

TYPE:boolDEFAULT:True

unicode_escape

IfTrue, decode UTF-16 escape sequences found inJSONPath string literals.

TYPE:boolDEFAULT:True

well_typed

Control well-typedness checks on filter function expressions.IfTrue (the default), JSONPath expressions are checked forwell-typedness as compile time.

New in version 0.10.0

TYPE:boolDEFAULT:True

Class attributes

ATTRIBUTEDESCRIPTION
fake_root_token

The pattern used to select a "fake" root node, one levelabove the real root node.

TYPE:str

filter_context_token

The pattern used to select extra filter contextdata. Defaults to"_".

TYPE:str

intersection_token

The pattern used as the intersection operator.Defaults to"&".

TYPE:str

key_token

The pattern used to identify the current key or index whenfiltering a, mapping or sequence. Defaults to"#".

TYPE:str

keys_selector_token

The pattern used as the "keys" selector. Defaults to"~".

TYPE:str

lexer_class

The lexer to use when tokenizing path strings.

TYPE:Type[Lexer]

max_int_index

The maximum integer allowed when selecting array items byindex. Defaults to(2**53) - 1.

TYPE:int

min_int_index

The minimum integer allowed when selecting array items byindex. Defaults to-(2**53) + 1.

TYPE:int

parser_class

The parser to use when parsing tokens from the lexer.

TYPE:Type[Parser]

root_token

The pattern used to select the root node in a JSON document.Defaults to"$".

TYPE:str

self_token

The pattern used to select the current node in a JSONdocument. Defaults to"@"

TYPE:str

union_token

The pattern used as the union operator. Defaults to"|".

TYPE:str

filter_cachinginstance-attribute

filter_caching:bool=filter_caching

Enable or disable filter expression caching.

function_extensionsinstance-attribute

function_extensions:Dict[str,Callable[...,Any]]={}

A list of function extensions available to filters.

lexerinstance-attribute

lexer:Lexer=lexer_class(env=self)

The lexer bound to this environment.

parserinstance-attribute

parser:Parser=parser_class(env=self)

The parser bound to this environment.

unicode_escapeinstance-attribute

unicode_escape:bool=unicode_escape

Enable or disable decoding of UTF-16 escape sequences found inJSONPath string literals.

well_typedinstance-attribute

well_typed:bool=well_typed

Control well-typedness checks on filter function expressions.

check_well_typedness

check_well_typedness(token:Token,func:FilterFunction,args:List[FilterExpression],)->None

Check the well-typedness of a function's arguments at compile-time.

compare

compare(left:object,operator:str,right:object)->bool

Object comparison within JSONPath filters.

Override this to customize filter expression comparison operatorbehavior.

PARAMETERDESCRIPTION
left

The left hand side of the comparison expression.

TYPE:object

operator

The comparison expression's operator.

TYPE:str

right

The right hand side of the comparison expression.

TYPE:object

RETURNSDESCRIPTION
bool

True if the comparison betweenleft andright, with the

bool

givenoperator, is truthy.False otherwise.

compile

compile(path:str)->Union[JSONPath,CompoundJSONPath]

Prepare a path string ready for repeated matching against different data.

PARAMETERDESCRIPTION
path

A JSONPath as a string.

TYPE:str

RETURNSDESCRIPTION
Union[JSONPath,CompoundJSONPath]

AJSONPath orCompoundJSONPath, ready to match against some data.Expect aCompoundJSONPath if the path string uses theunion orintersection operators.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
path

The JSONPath as a string.

TYPE:str

data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
List[object]

A list of matched objects. If there are no matches, the list willbe empty.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
path

The JSONPath as a string.

TYPE:str

data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Iterable[JSONPathMatch]

An iterator yieldingJSONPathMatch objects for each match.

RAISESDESCRIPTION
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

getitem(obj:Any,key:Any)->Any

Sequence and mapping item getter used throughout JSONPath resolution.

The default implementation ofgetitem simply callsoperators.getitem()from Python's standard library. Same asobj[key].

PARAMETERDESCRIPTION
obj

A mapping or sequence that might containkey.

TYPE:Any

key

A mapping key, sequence index or sequence slice.

TYPE:Any

getitem_asyncasync

getitem_async(obj:Any,key:object)->Any

An async sequence and mapping item getter.

is_truthy

is_truthy(obj:object)->bool

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.

PARAMETERDESCRIPTION
obj

Any object.

TYPE:object

RETURNSDESCRIPTION
bool

True if the object exists and is notFalse or0.

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.

PARAMETERDESCRIPTION
path

The JSONPath as a string.

TYPE:str

data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Union[JSONPathMatch, None]

AJSONPathMatch object for the first match, orNone if there wereno matches.

RAISESDESCRIPTION
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.

for match in jsonpath.query("$.foo..bar", data):    ...

You can skip and limit results withQuery.skip() andQuery.limit().

matches = (    jsonpath.query("$.foo..bar", data)    .skip(5)    .limit(10))for match in matches    ...

Query.tail() will get the lastn results.

for match in jsonpath.query("$.foo..bar", data).tail(5):    ...

Get values for each match usingQuery.values().

for obj in jsonpath.query("$.foo..bar", data).limit(5).values():    ...
PARAMETERDESCRIPTION
path

The JSONPath as a string.

TYPE:str

data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Query

A query iterator.

RAISESDESCRIPTION
JSONPathSyntaxError

If the path is invalid.

JSONPathTypeError

If a filter expression attempts to use types inan incompatible way.

setup_function_extensions

setup_function_extensions()->None

Initialize function extensions.

validate_function_extension_signature

validate_function_extension_signature(token:Token,args:List[Any])->List[Any]

Compile-time validation of function extension arguments.

RFC 9535 requires us to reject paths that use filter functions withtoo many or too few arguments.

jsonpath.JSONPathMatch

A matched object with a concrete path.

ATTRIBUTEDESCRIPTION
children

Matched child nodes. This will only be populated afterall children have been visited, usually by usingfindall()orlist(finditer()).

TYPE:List[JSONPathMatch]

obj

The matched object.

TYPE:object

parent

The immediate parent to this match in the JSON document.If this is the root node,parent will beNone.

TYPE:Optional[JSONPathMatch]

path

The canonical string representation of the path to this match.

TYPE:str

parts

The keys, indices and/or slices that make up the path to thismatch.

TYPE:Tuple[PathPart, ...]

root

A reference to the root node in the JSON document.

TYPE:Union[Sequence[Any],Mapping[str,Any]]

valueproperty

value:object

Return the value associated with this match/node.

add_child

add_child(*children:JSONPathMatch)->None

Append one or more children to this match.

filter_context

filter_context()->FilterContextVars

Return filter context data for this match.

pointer

pointer()->JSONPointer

Return aJSONPointer pointing to this match's path.

jsonpath.JSONPath

A compiled JSONPath ready to be applied to a JSON string or Python object.

PARAMETERDESCRIPTION
env

TheJSONPathEnvironment this path is bound to.

TYPE:JSONPathEnvironment

selectors

An iterable ofJSONPathSelector objects, as generated byaParser.

TYPE:Iterable[JSONPathSelector]

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:boolDEFAULT:False

ATTRIBUTEDESCRIPTION
env

TheJSONPathEnvironment this path is bound to.

selectors

TheJSONPathSelector instances that make up this path.

empty

empty()->bool

ReturnTrue if this path has no selectors.

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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
List[object]

A list of matched objects. If there are no matches, the list will

List[object]

be empty.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Iterable[JSONPathMatch]

An iterator yieldingJSONPathMatch objects for each match.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Union[JSONPathMatch, None]

AJSONPathMatch object for the first match, orNone if there wereno matches.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Query

A query iterator.

RAISESDESCRIPTION
JSONPathSyntaxError

If the path is invalid.

JSONPathTypeError

If a filter expression attempts to use types inan incompatible way.

singular_query

singular_query()->bool

ReturnTrue if this JSONPath query is a singular query.

jsonpath.CompoundJSONPath

MultipleJSONPaths 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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
List[object]

A list of matched objects. If there are no matches, the list willbe empty.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Iterable[JSONPathMatch]

An iterator yieldingJSONPathMatch objects for each match.

RAISESDESCRIPTION
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(path:JSONPath)->CompoundJSONPath

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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Union[JSONPathMatch, None]

AJSONPathMatch object for the first match, orNone if there wereno matches.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
data

A JSON document or Python object implementing theSequenceorMapping interfaces.

TYPE:Union[str,IOBase,Sequence[Any],Mapping[str,Any]]

filter_context

Arbitrary data made available to filters usingthefilter context selector.

TYPE:Optional[FilterContextVars]DEFAULT:None

RETURNSDESCRIPTION
Query

A query iterator.

RAISESDESCRIPTION
JSONPathSyntaxError

If the path is invalid.

JSONPathTypeError

If a filter expression attempts to use types inan incompatible way.

union

union(path:JSONPath)->CompoundJSONPath

Union of this path and another path.

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.

PARAMETERDESCRIPTION
it

AJSONPathMatch iterable, as you'd get fromjsonpath.finditer() orJSONPathEnvironment.finditer().

TYPE:Iterable[JSONPathMatch]

New in version 1.1.0

drop

drop(n:int)->Query

Skip up ton matches from the query iterator.

RAISESDESCRIPTION
ValueError

Ifn < 0.

first

first(n:int)->Query

Limit the query iterator to at most the firstn matches.

first() is an alias forlimit().

RAISESDESCRIPTION
ValueError

Ifn < 0.

first_one

first_one()->Optional[JSONPathMatch]

Return the firstJSONPathMatch orNone if there were no matches.

head

head(n:int)->Query

Limit the query iterator to at most the firstn matches.

head() is an alias forlimit().

RAISESDESCRIPTION
ValueError

Ifn < 0.

items

items()->Iterable[Tuple[str,object]]

Return an iterable of (path, object) tuples, one for each match.

last

last(n:int)->Query

Drop up to the lastn matches from the iterator.

last() is an alias fortail().

RAISESDESCRIPTION
ValueError

Ifn < 0.

last_one

last_one()->Optional[JSONPathMatch]

Return the lastJSONPathMatch orNone if there were no matches.

limit

limit(n:int)->Query

Limit the query iterator to at mostn matches.

RAISESDESCRIPTION
ValueError

Ifn < 0.

locations

locations()->Iterable[str]

Return an iterable of normalized paths, one for each match.

one

one()->Optional[JSONPathMatch]

Return the firstJSONPathMatch orNone if there were no matches.

one() is an alias forfirst_one().

pointers

pointers()->Iterable[JSONPointer]

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.

PARAMETERDESCRIPTION
expressions

One or more JSONPath query expressions to select relativeto each match in this query iterator.

TYPE:Union[str,JSONPath,CompoundJSONPath]DEFAULT:()

projection

The style of projection used when selecting values. Can beone ofProjection.RELATIVE,Projection.ROOT orProjection.FLAT.Defaults toProjection.RELATIVE.

TYPE:ProjectionDEFAULT:RELATIVE

RETURNSDESCRIPTION
Iterable[object]

An iterable of objects built from selectingexpressions relative toeach match from the current query.

New in version 1.2.0

skip

skip(n:int)->Query

Skip up ton matches from the query iterator.

RAISESDESCRIPTION
ValueError

Ifn < 0.

tail

tail(n:int)->Query

Drop matches up to the lastn matches from the iterator.

RAISESDESCRIPTION
ValueError

Ifn < 0.

take

take(n:int)->Query

Return a new query iterating over the nextn matches.

It is safe to continue using this query after calling take.

tee

tee(n:int=2)->Tuple[Query,...]

Returnn independent queries by teeing this query's iterator.

It is not safe to use aQuery instance after callingtee().

values

values()->Iterable[object]

Return an iterable of objects associated with each match.

jsonpath.Projection

Bases:Enum

Projection style used byQuery.select().

FLATclass-attributeinstance-attribute

FLAT=auto()

All selections are appended to a new array/list, without arrays and objectson the path to the selected value.

RELATIVEclass-attributeinstance-attribute

RELATIVE=auto()

The default projection. Selections include parent arrays and objects relativeto the JSONPathMatch.

ROOTclass-attributeinstance-attribute

ROOT=auto()

Selections include parent arrays and objects relative to the root JSON value.

jsonpath.function_extensions.FilterFunction

Bases:ABC

Base class for typed function extensions.

arg_typesabstractmethodproperty

arg_types:List[ExpressionType]

Argument types expected by the filter function.

return_typeabstractmethodproperty

return_type:ExpressionType

The type of the value returned by the filter function.

__call__abstractmethod

__call__(*args:Any,**kwds:Any)->Any

Called 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.

PARAMETERDESCRIPTION
pointer

A string representation of a JSON Pointer.

TYPE:str

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.unicode_escape anduri_decode are ignored ifparts is given.

TYPE:Tuple[Union[int, str], ...]DEFAULT:()

unicode_escape

IfTrue, UTF-16 escape sequences will be decodedbefore parsing the pointer.

TYPE:boolDEFAULT:True

uri_decode

IfTrue, the pointer will be unescaped usingurllibbefore being parsed.

TYPE:boolDEFAULT:False

ATTRIBUTEDESCRIPTION
keys_selector

The non-standard token used to target a mappingkey or name.

TYPE:str

max_int_index

The maximum integer allowed when resolving arrayitems by index. Defaults to(2**53) - 1.

TYPE:int

min_int_index

The minimum integer allowed when resolving arrayitems by index. Defaults to-(2**53) + 1.

TYPE:int

__truediv__

__truediv__(other:object)->JSONPointer

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

exists(data:Union[str,IOBase,Sequence[object],Mapping[str,object]])->bool

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.

PARAMETERDESCRIPTION
data

The target JSON "document" or equivalent Python objects.

TYPE:Union[str,IOBase,Sequence[object],Mapping[str, object]]

RETURNSDESCRIPTION
bool

True if this pointer can be resolved againstdata, orFalseotherwise.

New in version 0.9.0

from_matchclassmethod

from_match(match:JSONPathMatch)->JSONPointer

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.

PARAMETERDESCRIPTION
parts

The keys, indices and/or slices that make up a JSONPointer.

TYPE:Iterable[Union[int, str]]

unicode_escape

IfTrue, UTF-16 escape sequences will be decodedbefore parsing the pointer.

TYPE:boolDEFAULT:True

uri_decode

IfTrue, the pointer will be unescaped usingurllibbefore being parsed.

TYPE:boolDEFAULT:False

RETURNSDESCRIPTION
JSONPointer

A newJSONPointer built fromparts.

is_relative_to

is_relative_to(other:JSONPointer)->bool

ReturnTrue if this pointer points to a child ofother.

join

join(*parts:str)->JSONPointer

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

parent()->JSONPointer

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.

PARAMETERDESCRIPTION
data

The target JSON "document" or equivalent Python objects.

TYPE:Union[str,IOBase,Sequence[object],Mapping[str, object]]

default

A default value to return if the pointer can't be resolvedagainst the given data.

TYPE:objectDEFAULT:UNDEFINED

RETURNSDESCRIPTION
object

The object indata pointed to by this pointer.

RAISESDESCRIPTION
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.

PARAMETERDESCRIPTION
data

The target JSON "document" or equivalent Python objects.

TYPE:Union[str,IOBase,Sequence[object],Mapping[str, object]]

RETURNSDESCRIPTION
Tuple[Union[Sequence[object],Mapping[str, object], None], object]

A(parent, object) tuple, where parent will beNone if thispointer points to the root node in the document. If the parentexists but the last object does not,(parent, UNDEFINED) willbe returned.

RAISESDESCRIPTION
JSONPointerIndexError

When attempting to access a sequence byan out of range index, unless using the special- index.

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.

PARAMETERDESCRIPTION
rel

ARelativeJSONPointer or a string following "Relative JSONPointer" syntax.

TYPE:Union[RelativeJSONPointer, str]

unicode_escape

IfTrue, UTF-16 escape sequences will be decodedbefore parsing the pointer.

TYPE:boolDEFAULT:True

uri_decode

IfTrue, the pointer will be unescaped usingurllibbefore being parsed.

TYPE:boolDEFAULT:False

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

PARAMETERDESCRIPTION
rel

A string following Relative JSON Pointer syntax.

TYPE:str

unicode_escape

IfTrue, UTF-16 escape sequences will be decodedbefore parsing the pointer.

TYPE:boolDEFAULT:True

uri_decode

IfTrue, the pointer will be unescaped usingurllibbefore being parsed.

TYPE:boolDEFAULT:False

to

to(pointer:Union[JSONPointer,str],*,unicode_escape:bool=True,uri_decode:bool=False)->JSONPointer

Return a new JSONPointer relative topointer.

PARAMETERDESCRIPTION
pointer

AJSONPointer instance or a string following JSONPointer syntax.

TYPE:Union[JSONPointer, str]

unicode_escape

IfTrue, UTF-16 escape sequences will be decodedbefore parsing the pointer.

TYPE:boolDEFAULT:True

uri_decode

IfTrue, the pointer will be unescaped usingurllibbefore being parsed.

TYPE:boolDEFAULT:False

jsonpath.JSONPatch

Modify JSON-like data with JSON Patch.

RFC 6902 defines operations to manipulate a JSON document.JSONPatchsupports parsing and applying standard JSON Patch formatted operations,and provides a Python builder API following the same semantics as RFC 6902.

PARAMETERDESCRIPTION
ops

A JSON Patch formatted document or equivalent Python objects.

TYPE:Union[str,IOBase,Iterable[Mapping[str, object]], None]DEFAULT:None

unicode_escape

IfTrue, UTF-16 escape sequences will be decodedbefore parsing JSON pointers.

TYPE:boolDEFAULT:True

uri_decode

IfTrue, JSON pointers will be unescaped usingurllibbefore being parsed.

TYPE:boolDEFAULT:False

RAISESDESCRIPTION
JSONPatchError

Ifops is given and any of the provided operationsis malformed.

add

add(path:Union[str,JSONPointer],value:object)->Self

Append anadd operation to this patch.

PARAMETERDESCRIPTION
path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

value

The object to add.

TYPE:object

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

addap

addap(path:Union[str,JSONPointer],value:object)->Self

Append anaddap operation to this patch.

PARAMETERDESCRIPTION
path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

value

The object to add.

TYPE:object

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

addne

addne(path:Union[str,JSONPointer],value:object)->Self

Append anaddne operation to this patch.

PARAMETERDESCRIPTION
path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

value

The object to add.

TYPE:object

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

apply

apply(data:Union[str,IOBase,MutableSequence[object],MutableMapping[str,object],])->object

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.

PARAMETERDESCRIPTION
data

The target JSON "document" or equivalent Python objects.

TYPE:Union[str,IOBase,MutableSequence[object],MutableMapping[str, object]]

RETURNSDESCRIPTION
object

Modified input data.

RAISESDESCRIPTION
JSONPatchError

When a patch operation fails.

JSONPatchTestFailure

When atest operation does not pass.JSONPatchTestFailure is a subclass ofJSONPatchError.

asdicts

asdicts()->List[Dict[str,object]]

Return a list of this patch's operations as dictionaries.

copy

copy(from_:Union[str,JSONPointer],path:Union[str,JSONPointer],)->Self

Append acopy operation to this patch.

PARAMETERDESCRIPTION
from_

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

move

move(from_:Union[str,JSONPointer],path:Union[str,JSONPointer],)->Self

Append amove operation to this patch.

PARAMETERDESCRIPTION
from_

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

remove

remove(path:Union[str,JSONPointer])->Self

Append aremove operation to this patch.

PARAMETERDESCRIPTION
path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

replace

replace(path:Union[str,JSONPointer],value:object)->Self

Append areplace operation to this patch.

PARAMETERDESCRIPTION
path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

value

The object to add.

TYPE:object

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.

test

test(path:Union[str,JSONPointer],value:object)->Self

Append a test operation to this patch.

PARAMETERDESCRIPTION
path

A string representation of a JSON Pointer, or one that hasalready been parsed.

TYPE:Union[str,JSONPointer]

value

The object to test.

TYPE:object

RETURNSDESCRIPTION
Self

ThisJSONPatch instance, so we can build a JSON Patch by chainingcalls to JSON Patch operation methods.


[8]ページ先頭

©2009-2025 Movatter.jp