h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
558 stars 84 forks source link

JSON path parser fails to parse comma-separated array indexes #169

Open aovchinnikov opened 2 months ago

aovchinnikov commented 2 months ago

Env:

The following code returns parser error:

from jsonpath_ng.ext import parse

jsonpath_expr = parse('$.commands[0,1].test_prop')

jsonpath_expr = parse('$.commands[0,1].tester') File "C:\Python38\lib\site-packages\jsonpath_ng\ext\parser.py", line 174, in parse return ExtentedJsonPathParser(debug=debug).parse(path) File "C:\Python38\lib\site-packages\jsonpath_ng\parser.py", line 38, in parse return self.parse_token_stream(lexer.tokenize(string)) File "C:\Python38\lib\site-packages\jsonpath_ng\parser.py", line 62, in parse_token_stream return new_parser.parse(lexer = IteratorToTokenStream(token_iterator)) File "C:\Python38\lib\site-packages\ply\yacc.py", line 333, in parse return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc) File "C:\Python38\lib\site-packages\ply\yacc.py", line 1201, in parseopt_notrack tok = call_errorfunc(self.errorfunc, errtoken, self) File "C:\Python38\lib\site-packages\ply\yacc.py", line 192, in call_errorfunc r = errorfunc(token) File "C:\Python38\lib\site-packages\jsonpath_ng\parser.py", line 78, in p_error raise JsonPathParserError('Parse error at %s:%s near token %s (%s)' jsonpath_ng.exceptions.JsonPathParserError: Parse error at 1:12 near token , (,)

bjerzyna commented 3 days ago

Another attempt to get this changed: https://github.com/h2non/jsonpath-ng/pull/173