#Python #Javascript #JSON #nested-array-object
$ pip install objectpath $$ objectpath
In weather readings find cities where temperature is higher than 25°C and the sky is clear.
$ points to the root of the document. It can be either object or a list of objects. ObjectPath queries works for both! Here the JSON document describes weather readings within provided geopraphic coordinates.
@ points to current item from the list generated from executing expression on the left side of []. Here we check if temperature in each city is greater than 25°C.
.. finds all objects in the subtree. Here it selects all objects from the readings.
* selects all objects from array. This is a helper for .. operator.
. goes one level deeper into data structure (selects child of a parent). In conjunction with property name like .temp and array of objects it returns array of values under each object's temp attribute.More at paths reference
[] is an advanaced tool for filtering lists of objects. It can do almost anything! More at selectors reference
Start by reading the tutorial. Install in Python or Javascript. Reference manual will help in daily job. Report bugs via Github issues, discuss on Google Groups.
So you've got that amazing set of data from an API, but all you see is a chunk of random JSON? ObjectPath shell can help you navigate this mess. Just do:
$ ObjectPath -u //URL-to-API/call
ObjectPath interactive shell
ctrl+c to exit.
Loading JSON document from //URL-to-API/call done.>>> $.*
{
"cod":"200",
"calctime":0.0082,
"cnt" :15,
"list" :[{
"id" :2217362,
"name":"Gharyan"
...
Easy to start with and suitable for complex data-discovery jobs.
Allows for working with big nested tree structures. Up to the size of your RAM.
Available in JS and Python.