Skip to content

Filters not implemented #54

Open
Open
@aguynamedben

Description

@aguynamedben

Hi, 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 ?() 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions