h2non / jsonpath-ng

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

filter.Expresson.find() does not handle 'None' values correctly #153

Open code-inflation opened 7 months ago

code-inflation commented 7 months ago

find() doesn't seem to be able to handle None values.

Example:

from jsonpath_ng.ext.parser import parse

data = [{"test": True}, {"test": None}]

query = $[?(test == true)]
parser = parse(query)
parser.find(data)

Causes the following error:

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
amittendulkar commented 3 months ago

Minor correction above. Instead of , query = $[?(test == true)] should be, query = '$[?(test == true)]'

Dggz commented 6 days ago

Is there any chance this will be fixed? Or is there a chance that PRs addressing this will be merged and released? Is this library still maintained at all?

This part of the code is at least part of the issue since True/False are instances of int, that whole conditional block is broken and it works for actual booleans by chance.

https://github.com/h2non/jsonpath-ng/blame/8a62341c1ad94b7c23427a96dd6ea81367d537b7/jsonpath_ng/ext/filter.py#L107