gpt4 book ai didi

Python JSONPath 过滤器表达式错误,jsonpath-rw 1.4.0 的意外字符

转载 作者:太空宇宙 更新时间:2023-11-04 00:32:49 28 4
gpt4 key购买 nike

我安装了 jsonpath-rw 1.4.0

sudo apt-get install python-jsonpath-rw

它带有一个 /usr/bin/jsonpath。但这在使用过滤器表达式时给我带来了错误:

$ 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: ?

那么jsonpath-rw 1.4.0是不是不支持Filter表达式了?

好像是working fine according to this blog post ,但那是在 2015 年。

从那以后情况有变化吗?

最佳答案

我通过使用 jsonpath-rw-ext 而不是 jsonpath-rw 使它工作。这似乎是支持过滤器扩展的那个。

关于Python JSONPath 过滤器表达式错误,jsonpath-rw 1.4.0 的意外字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45175339/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com