You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the split extension only allows positive indexes for its segments. However, I want to pick the very last segment, and their quantity is arbitrary.
My workaround so far is extending the parser just for a small regex tweak:
fromjsonpath_ng.ext.parserimportExtentedJsonPathParserfromjsonpath_ng.ext.stringimportSplitSPLIT_NEGATIVE_INDEXABLE=re.compile(r"split\((.),\s+(-?\d+),\s+(\d+|-1)\)")
classSplitNegativeIndexable(Split):
def__init__(self, method=None):
m=SPLIT_NEGATIVE_INDEXABLE.match(method)
self.char=m.group(1)
self.segment=int(m.group(2))
self.max_split=int(m.group(3))
self.method=methodclassJsonPathParser(ExtentedJsonPathParser):
"""we need a docstring here otherwise jsonpath-rw starts grumbling"""defp_jsonpath_named_operator(self, p):
"jsonpath : NAMED_OPERATOR"ifp[1].startswith("split("):
p[0] =SplitNegativeIndexable(p[1])
else:
super().p_jsonpath_named_operator(p)
I can send a proper PR once I finish working for today.
The text was updated successfully, but these errors were encountered:
Currently, the
split
extension only allows positive indexes for its segments. However, I want to pick the very last segment, and their quantity is arbitrary.My workaround so far is extending the parser just for a small regex tweak:
I can send a proper PR once I finish working for today.
The text was updated successfully, but these errors were encountered: