Filters not implemented
See original GitHub issueHi, thanks for your work on making a jsonpath library for Python.
I think this library might have a bug or are missing this part of the spec:
using the symbol ‘@’ for the current object. Filter expressions are supported via the syntax ?(<boolean expr>) as in
$.store.book[?(@.price < 10)].title
…
$…book[?(@.isbn)] | filter all books with isbn number $…book[?(@.price<10)] | filter all books cheapier than 10
I’m trying to filter an array by a string. My query, `$.phoneNumbers[?(@.type==‘home’)].number, works fine on the jsonpath.com testing tool, but I can’t get it working using jsonpath-ng. It fails to parse the query, complaining about the question mark.
Example code:
import json
from jsonpath_rw import jsonpath, parse
data = '''
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
'''
data = json.loads(data)
jsonpath_expr = parse(data)
jsonpath_query = "$.phoneNumbers[?(@.type=='home')].number"
Exception: JsonPathLexerError: Error on line 1, col 15: Unexpected character: ?
I’m trying this with jsonpath-rw>=1.4.0
Any ideas? Am I doing something wrong?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:14 (1 by maintainers)
Just a note for those looking for negation on filtering… eg.
$[?(!@.nonExistantField)]
you can find it in this PR: https://github.com/h2non/jsonpath-ng/pull/21. Note you need to import parse from jsonpath_ng.extand
jsonpath2