h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
582 stars 85 forks source link

support dictionary filtering #41

Closed josephwhite13 closed 4 years ago

josephwhite13 commented 4 years ago

When filtering a dictionary, we can apply the filter on dictionary.values().

>>> from jsonpath_ng import jsonpath
>>> from jsonpath_ng.ext import parse
>>> simple_dict = {
  "phone_numbers": {
    "1":{
      "type"  : "iPhone",
      "number": "0123-4567-8888"
    },
    "2":{
      "type"  : "home",
      "number": "0123-4567-8910"
    },
    "3":{
      "type"  : "home",
      "number": "1098-7654-3210"
    }
  }
}
>>> expression = parse('$.phone_numbers[?(@.type == "home")]')
>>> print([x.value for x in expression.find(simple_dict)])
[{'type': 'home', 'number': '0123-4567-8910'}, {'type': 'home', 'number': '1098-7654-3210'}]

This should resolve #16 and resolve #19. If there is any additional info I need to provide, feel free to reach out!

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 0.0% when pulling c7d8b7581fbfd8c58656f0e956fd8afeb3fc5e79 on josephwhite13:allow-dictionary-filtering into e5405c1adc9b90aa081595d4982833f6f2a2893a on h2non:master.

squioc commented 4 years ago

Hello @h2non, do you know if and when this pull request could be merged? Thanks

iamyourexpert commented 4 years ago

@h2non Will this be pushed into pypi as 1.5.2? Thanks

squioc commented 4 years ago

Great. Thanks 👍

h2non commented 4 years ago

v1.5.2 is out on PyPI. Apologies for the delay!