Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonPathParserError when property name starts with "true" or "false #177

Open
dgDSA opened this issue Aug 26, 2024 · 2 comments
Open

JsonPathParserError when property name starts with "true" or "false #177

dgDSA opened this issue Aug 26, 2024 · 2 comments
Labels

Comments

@dgDSA
Copy link

dgDSA commented Aug 26, 2024

A JsonPathParserError is raised when a JsonPath property starts with the word "true" or "false", e.g.:

Python 3.10.13 (main, Apr 22 2024, 14:22:37) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import jsonpath_ng, jsonpath_ng.ext
jsonpath_ng.version
'1.6.1'
jsonpath_ng.ext.parser.parse("trueName")
Traceback (most recent call last):
File "", line 1, in
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/jsonpath_ng/ext/parser.py", line 174, in parse
return ExtentedJsonPathParser(debug=debug).parse(path)
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/jsonpath_ng/parser.py", line 38, in parse
return self.parse_token_stream(lexer.tokenize(string))
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/jsonpath_ng/parser.py", line 62, in parse_token_stream
return new_parser.parse(lexer = IteratorToTokenStream(token_iterator))
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/ply/yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/ply/yacc.py", line 1201, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/ply/yacc.py", line 192, in call_errorfunc
r = errorfunc(token)
File "/home/dg/ConnectedVehicle.git/pyotx/_3rdparty/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:0 near token True (BOOL)

Note: I found the bug while testing corner cases. Thus, this bug report is very low priority for me.

@michaelmior
Copy link
Collaborator

@dgDSA Would you be able to provide a complete example that reproduces this bug?

@dgDSA
Copy link
Author

dgDSA commented Oct 21, 2024

Actually, the one line from my original comment is enough to reproduce the bug:
jsonpath_ng.ext.parser.parse("trueName")

Here is another, more comprehensive example:

import json
import jsonpath_ng.ext

json_object = json.loads('{"problems_detected": 4, "false_positives": 2}')

expression1 = jsonpath_ng.ext.parser.parse("problems_detected")
print(f"Expression 1 match: {expression1.find(json_object)[0].value}")

expression2 = jsonpath_ng.ext.parser.parse("false_positives")
print(f"Expression 2 match: {expression2.find(json_object)[0].value}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@michaelmior @dgDSA and others