sileht / python-jsonpath-rw-ext

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

Filtering with booleans #10

Closed exvito closed 7 years ago

exvito commented 8 years ago

Hello @sileht, thanks for sharing this project.

I've been using jsonpath-rw for a while and now needed to do some filtering so I ended up finding jsonpath-rw-ext which seems to match exactly what I'm looking for.

However I got stuck at the point where I tried filtering based on boolean values in the data. It doesn't seem to work...

Example:

import jsonpath_rw_ext

data = [{"color": "blue", "flag": True}, {"color": "green", "flag": False}]
jsp = jsonpath_rw_ext.parse("$[?flag = True].color")
results = [match.value for match in jsp.find(data)]
print(results)

I expected this to produce results == ["blue"] but got [] instead.

I digged in a little bit and it seems to comes down to the fact that the True in the flag = True expression ends up as a string "True" in the Expression instance self.value in _filters.py (instead of ending up as a boolean True). Digging further, points to a limitation in the lexer/parser in jsonpath-rw codebase.

Questions:

Again thanks for sharing this code and for any feedback you may share.