(These days many api's over HTTP that we query return JSON. That is great and all, it is much more readable for humans than XML.
What about when there is a large set of JSON and you only need a small part of it?
There are different ways of doing it, like converting the json to a dictionary and looping through everything and filtering the data as you go.
This is not the way to go in my opinion...we should be querying JSON the same way we query a database.
I have come across 2 methods of querying:
JSONPath and will go through their applications in this post
YAQL: Yet another query language can be used to query json and yaml.
Read the YAQL Docs here.
I think the Yaql project is closely aligned with stackstorm and their orquesta markup language.
It has an Online YAQL Evaluator, which is kind of essential espescally when asking help from others.
Arose from the ability of Xpath to be used with HTML and XML and nothing similar for json.
Looks like it was created in 2007 by Stefan Goessnes, you can read the original docs.
More info on JSONPath
I recently found JMESPath, via the ansible documentation on querying JSON on the filters page.
Here are some JMESPath examples.
JQ is a command line tool
Update: Jan 2020
Someone on twitter recommended glom a new approach for working with data in python
I will certainly give this a go in a bit...