JSONPath
struct JSONPathA compiled RFC 9535 query.
Compiling separates the work that depends only on the query from the work that depends on the document, so a query used against many documents pays for parsing, validation and regular expression compilation once.
Implements Movable
- Fields
segments: List[_Segment]selectors: List[_Selector]queries: List[_QueryRef]exprs: List[_Expr]cmps: List[_Slot]funcs: List[_Func]args: List[_Slot]literals: List[Value]regexes: List[Regex]root: Int
__init__
def __init__(out self) compile
def compile(path: String) -> Self Parse and validate a query.
- Args
path: The query, which must be a completejsonpath-querywith no leading or trailing whitespace.
Raises Error: If path is not a valid RFC 9535 query. Section 2.1
requires an implementation to reject an invalid query
rather than guess at a meaning for it.
query
def query(self, document: Value) -> List[Value] The values of the nodes this query selects, in order.
paths
def paths(self, document: Value) -> List[String] The normalized paths of the nodes this query selects.
A normalized path (RFC 9535 section 2.7) is itself a query, in
a canonical form that names exactly one node: $['a'][0]. It
is not a JSON Pointer, and the two must not be swapped for each
other.
query_with_paths
def query_with_paths(self, document: Value) -> List[Tuple[String, Value]] Each selected node as its normalized path and its value.