question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filters not implemented

See original GitHub issue

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 ?(<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:open
  • Created 6 years ago
  • Reactions:14
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hrobertsoncommented, May 16, 2019

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.ext

1reaction
dmlb2000commented, Sep 29, 2018

and jsonpath2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query filters are not implemented for the FAISSDocumentStore
I have created a branching ES+DPR pipeline, where ES uses "filters". Unfortunatelly the filters are passed to the DPR retriever and this brings ......
Read more >
Comparison of these types is not implemented error when ...
I have a set of id's from a csv and I would like to filter out from a data fram all referrals that...
Read more >
BackgroundImage is not implemented in Filter Effects (CSS or ...
Issue 137230: BackgroundImage is not implemented in Filter Effects (CSS or SVG). Reported by schedule k...@actionmoniker.com k...@actionmoniker.com.
Read more >
Active filter - Wikipedia
Not to be confused with Active power filter. An active filter is a type of analog circuit implementing an electronic filter using active...
Read more >
Active Filters - an overview | ScienceDirect Topics
Active filters are so called because they use an active gain element (usually an operational amplifier) in addition to resistors and capacitors. They...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found