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 #39

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 #19. If there is any additional info I need to provide, feel free to reach out!

josephwhite13 commented 4 years ago

Issues with getting coveralls to trigger. Going to resubmit