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
I am trying to incorporate the below jsonpath to fetch an _id value from a json object based on a provided company name. While I test it out on the URL, I am getting my desired result. However, once I try to execute and parse the same jsonpath in my IDE, I am getting a traceback.
jsonpath : $[?(@.company=="GADTRON")]._id
PFA, the sample.txt file that contains the json object where I am trying the combinations.
I am also attaching a gif of the trials on the URL and the code traceback when it is executed.
Please Note : ? is a valid character literal among the jsonpath expressions, as mentioned in the example below: $.objects[?some_field = "foobar")]
Traceback :
--------------------------------------------------- Traceback (most recent call last): File "/workspace/ComplexFileParserPython/src/main.py", line 38, in <module> jsonpath_expr = parse('$[?(@.company=="GADTRON")]._id') File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 21, in parse return JsonPathParser().parse(string) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 44, in parse return self.parse_token_stream(lexer.tokenize(string)) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 67, in parse_token_stream return new_parser.parse(lexer = IteratorToTokenStream(token_iterator)) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/ply/yacc.py", line 1063, in parseopt_notrack lookahead = get_token() # Get the next token File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 193, in token return next(self.iterator) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/lexer.py", line 33, in tokenize t = new_lexer.token() File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/ply/lex.py", line 386, in token newtok = self.lexerrorf(tok) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/lexer.py", line 165, in t_error raise JsonPathLexerError('Error on line %s, col %s: Unexpected character: %s ' % (t.lexer.lineno, t.lexpos - t.lexer.latest_newline, t.value[0])) jsonpath_ng.exceptions.JsonPathLexerError: Error on line 1, col 2: Unexpected character: ?
successfully fetched the desired value on the URL :
Getting traceback when trying to execute the code in my IDE :
The text was updated successfully, but these errors were encountered:
SouvikDcoder
changed the title
Getting error for Unexpected character: ? while trying to evaluate a jsonpath
Getting error Unexpected character: ? while trying to evaluate a jsonpath
Oct 7, 2022
I am trying to incorporate the below jsonpath to fetch an
_id
value from a json object based on a provided company name. While I test it out on the URL, I am getting my desired result. However, once I try to execute and parse the same jsonpath in my IDE, I am getting a traceback.jsonpath :
$[?(@.company=="GADTRON")]._id
PFA, the sample.txt file that contains the json object where I am trying the combinations.
I am also attaching a gif of the trials on the URL and the code traceback when it is executed.
Traceback :
--------------------------------------------------- Traceback (most recent call last): File "/workspace/ComplexFileParserPython/src/main.py", line 38, in <module> jsonpath_expr = parse('$[?(@.company=="GADTRON")]._id') File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 21, in parse return JsonPathParser().parse(string) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 44, in parse return self.parse_token_stream(lexer.tokenize(string)) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 67, in parse_token_stream return new_parser.parse(lexer = IteratorToTokenStream(token_iterator)) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/ply/yacc.py", line 1063, in parseopt_notrack lookahead = get_token() # Get the next token File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/parser.py", line 193, in token return next(self.iterator) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/lexer.py", line 33, in tokenize t = new_lexer.token() File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/ply/lex.py", line 386, in token newtok = self.lexerrorf(tok) File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/jsonpath_ng/lexer.py", line 165, in t_error raise JsonPathLexerError('Error on line %s, col %s: Unexpected character: %s ' % (t.lexer.lineno, t.lexpos - t.lexer.latest_newline, t.value[0])) jsonpath_ng.exceptions.JsonPathLexerError: Error on line 1, col 2: Unexpected character: ?
sample.txt'
successfully fetched the desired value on the URL :
Getting traceback when trying to execute the code in my IDE :
The text was updated successfully, but these errors were encountered: