Python JSONPath2 Module¶
Contents:
The jsonpath2 module.
-
jsonpath2.match(path_str: str, root_value: object) → Generator[jsonpath2.node.MatchData, None, None][source]¶ Match root value of the path.
The
jsonpath2.matchfunction is a shortcut to match a given JSON data structure against a JSONPath string.>>> import jsonpath2 >>> doc = {'hello': 'Hello, world!'} >>> [x.current_value for x in jsonpath2.match('$.hello', doc)] ['Hello, world!']
Expression module.
-
class
jsonpath2.expression.Expression[source]¶ Add the expression methods to the jsonpath object.
-
_abc_impl= <_abc_data object>¶
-
The parse tree node module.
-
class
jsonpath2.node.MatchData(node, root_value, current_value)[source]¶ Match data object for storing node values.
The
jsonpath2.node.MatchDataclass represents the JSON value and context for a JSONPath match.This class is constructed with respect to a root JSON value, a current JSON value, and an abstract syntax tree node.
- Attributes:
root_valueThe root JSON value.current_valueThe current JSON value (i.e., the matching JSON value).nodeThe abstract syntax tree node.
-
class
jsonpath2.node.Node[source]¶ Node object for the jsonpath parsetree.
The
jsonpath2.node.Nodeclass represents the abstract syntax tree for a JSONPath.-
_abc_impl= <_abc_data object>¶
-
match(root_value: object, current_value: object) → Generator[jsonpath2.node.MatchData, None, None][source]¶ Abstract method to determine a node match.
Match the given root and current JSON data structures against this instance. For each match, yield an instance of the
jsonpath2.node.MatchDataclass.
-
The path module.
-
class
jsonpath2.path.Path(root_node: jsonpath2.nodes.root.RootNode)[source]¶ Path parsetree object.
The
jsonpath2.path.Pathclass represents a JSONPath.>>> s = '{"hello":"Hello, world!"}' '{"hello":"Hello, world!"}' >>> import json >>> d = json.loads(s) {'hello':'Hello, world!'} >>> from jsonpath2.path import Path >>> p = Path.parse_str('$["hello"]') <jsonpath2.path.Path object> >>> [match_data.current_value for match_data in p.match(d)] ['Hello, world!'] >>> [match_data.node.tojsonpath() for match_data in p.match(d)] ['$["hello"]']
This class is constructed with respect to the given instance of the
jsonpath2.nodes.root.RootNodeclass (viz., theroot_nodeproperty).- Attributes:
root_nodeThe root node of the abstract syntax tree for this instance.
-
match(root_value: object) → Generator[jsonpath2.node.MatchData, None, None][source]¶ Match root value of the path.
Match the given JSON data structure against this instance. For each match, yield an instance of the
jsonpath2.node.MatchDataclass.
The Subscript module.
-
class
jsonpath2.subscript.Subscript[source]¶ Subscript has no value beyond a node other than type.
-
_abc_impl= <_abc_data object>¶
-
A JSONPath abstract class.