Add jq filter#626
Conversation
|
Thanks for sharing this project with us! I'm not super well-versed in Python projects and this has been a good experience. I can see in the Travis job how to run tests and that I have some syntax issues in the documentation. I'll add a test or tests for this filter - is there anything in particular you want me to test for? I'll also clean up the documentation syntax issues I introduced. |
|
These documentation driven tests are pretty cool! I'll have to use them as inspiration later. Sorry for the disjointed commits - I normally try to keep things cleaner. This was a good learning experience! I'm excited to hear your thoughts! |
| json.loads(data) | ||
| except ValueError: | ||
| raise ValueError('The url response contained invalid JSON') | ||
|
|
||
| if 'query' not in subfilter: | ||
| raise ValueError('{} filter needs a query'.format(self.__kind__)) | ||
|
|
||
| if jq is None: | ||
| raise ImportError('Please install jq') | ||
|
|
||
| return jq.text(subfilter['query'], json.loads(data)) |
There was a problem hiding this comment.
One "optimization" here could be to store the result of json.loads(data) in line 878, and re-use the result in line 888 to not have to re-parse the JSON data.
thp
left a comment
There was a problem hiding this comment.
Nice and clean. One comment about avoiding double-parsing of JSON. Also, you could add this change to CHANGELOG.md.
|
Thanks for the feedback @thp! |
|
Merged, thanks! |
|
Appreciate this addition very much, nice work! |
Adds the ability to select content from JSON data using
jq- a lightweight JSON processor - filter syntax. Thejqfilters are similar to CSS or XPath selectors, with added operators to transform the data.Addresses #592 in a different way.