Convenience Functions
These package-level functions use the default JSONPathEnvironment, jsonpath.DEFAULT_ENV when strict=False, or the preconfigured strict environment, jsonpath.STRICT_ENV when strict=True.
jsonpath.compile
Prepare a path string ready for repeated matching against different data.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
A JSONPath as a string.
TYPE:
|
strict
|
When
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. |
jsonpath.findall
findall(
path: str,
data: JSONData,
*,
filter_context: Optional[FilterContextVars] = None,
strict: bool = False
) -> 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:
|
strict
|
When
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. |
jsonpath.finditer
finditer(
path: str,
data: JSONData,
*,
filter_context: Optional[FilterContextVars] = None,
strict: bool = False
) -> 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:
|
strict
|
When
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. |
jsonpath.findall_async
async
findall_async(
path: str,
data: JSONData,
*,
filter_context: Optional[FilterContextVars] = None,
strict: bool = False
) -> 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:
|
strict
|
When
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. |
jsonpath.finditer_async
async
finditer_async(
path: str,
data: JSONData,
*,
filter_context: Optional[FilterContextVars] = None,
strict: bool = False
) -> AsyncIterable[JSONPathMatch]
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:
|
strict
|
When
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AsyncIterable[JSONPathMatch]
|
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. |
jsonpath.match
The JSONPath match object, as returned from JSONPath.finditer().
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:
|
new_child
Return a new JSONPathMatch instance with this instance as its parent.
NodeList
jsonpath.query
query(
path: str,
data: JSONData,
*,
filter_context: Optional[FilterContextVars] = None,
strict: bool = False
) -> 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:
|
strict
|
When
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. |