Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python JSONPath Filter expressions error, Unexpected character for jsonpath-rw 1.4.0

I installed jsonpath-rw 1.4.0 with

sudo apt-get install python-jsonpath-rw

which comes with a /usr/bin/jsonpath. But that is giving me errors when using Filter expressions:

$ jsonpath '$..book[?(@.price < 10)]' book.json
Traceback (most recent call last):
  File "/usr/bin/jsonpath", line 11, in <module>
    load_entry_point('jsonpath-rw==1.4.0', 'console_scripts', 'jsonpath.py')()
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/bin/jsonpath.py", line 71, in entry_point
    main(*sys.argv)
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/bin/jsonpath.py", line 57, in main
    expr = parse(args.expression)
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/parser.py", line 14, in parse
    return JsonPathParser().parse(string)
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/parser.py", line 32, in parse
    return self.parse_token_stream(lexer.tokenize(string))
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/parser.py", line 55, in parse_token_stream
    return new_parser.parse(lexer = IteratorToTokenStream(token_iterator))
  File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 1061, in parseopt_notrack
    lookahead = get_token()     # Get the next token
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/parser.py", line 179, in token
    return next(self.iterator)
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/lexer.py", line 33, in tokenize
    t = new_lexer.token()
  File "/usr/lib/python2.7/dist-packages/ply/lex.py", line 393, in token
    newtok = self.lexerrorf(tok)
  File "/usr/lib/python2.7/dist-packages/jsonpath_rw/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_rw.lexer.JsonPathLexerError: Error on line 1, col 8: Unexpected character: ? 

So does jsonpath-rw 1.4.0 not support Filter expressions?

It seems to be working fine according to this blog post, but that's in 2015.

Has things changed since then?

like image 627
xpt Avatar asked Jun 23 '26 22:06

xpt


1 Answers

I got this working by using jsonpath-rw-ext instead of jsonpath-rw. This seems to be the one that has support for the filter extensions.

like image 53
Mike Avatar answered Jun 25 '26 11:06

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!