sileht / python-jsonpath-rw-ext

Extensions for JSONPath RW
Apache License 2.0
59 stars 19 forks source link

Why do filter only work on lists? #27

Open Ronserruya opened 4 years ago

Ronserruya commented 4 years ago

I initially opened this issue on the jsonpath-ng repo, but it looks like the filtering there was just taken from this repo.

https://github.com/h2non/jsonpath-ng/issues/30

In order to get the facebook URL from this:

{
   "websites":{
      "items":[
         {
            "type":"Website",
            "properties":{
               "updated_at":1553902435,
               "website_name":"homepage",
               "website_type":"homepage",
               "created_at":1395793311,
               "url":"http://***.com"
            }
         },
         {
            "type":"Website",
            "properties":{
               "updated_at":1553902435,
               "website_name":"facebook",
               "website_type":"facebook",
               "created_at":1395793311,
               "url":"https://www.facebook.com/***"
            }
         },
         {
            "type":"Website",
            "properties":{
               "updated_at":1553902435,
               "website_name":"twitter",
               "website_type":"twitter",
               "created_at":1395793311,
               "url":"https://www.twitter.com/***"
            }
         }
      ]
   }
}

I need to use websites.items[?(@.properties.website_type == 'facebook')].properties.url

Why does websites.items.[*].properties[?(@.website_type == 'facebook')].url not work?

or parse('a[?(@.b > 1)]').find({'a': {'b': 2}}), they work with other online implementations like http://jsonpath.herokuapp.com/