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:
Do you have any suggestion for a workaround that does not involve pre-processing the data?
Do you think a fix for this could be made at the jsonpath-rw-ext level or would it need to go into jsonpath-rw's codebase?
Lastly: you mention that these extensions would be proposed to be integrated into jsonpath-rw. Any progress on that?
Again thanks for sharing this code and for any feedback you may share.
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:
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 theflag = True
expression ends up as a string"True"
in theExpression
instanceself.value
in _filters.py (instead of ending up as a booleanTrue
). 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.