-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
27 lines (22 loc) · 943 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from jsonpath_ng.ext.parser import ExtentedJsonPathParser
from . import ext_functions as fn
# You must use this parser instead of the normal or ext one.
class JsonPathParser(ExtentedJsonPathParser):
"Aether extension of jsonpath_ng extensions..."
# register all exposed functions in this method
def p_jsonpath_named_operator(self, p):
"jsonpath : NAMED_OPERATOR"
if p[1].startswith("splitlist("):
p[0] = fn.SplitList(p[1])
elif p[1].startswith("cast("):
p[0] = fn.Cast(p[1])
elif p[1].startswith("match("):
p[0] = fn.Match(p[1])
elif p[1].startswith("notmatch("):
p[0] = fn.NotMatch(p[1])
elif p[1].startswith("datetime("):
p[0] = fn.ParseDatetime(p[1])
else:
super(JsonPathParser, self).p_jsonpath_named_operator(p)
def parse(path, debug=False):
return JsonPathParser(debug=debug).parse(path)