The agile query language for semi-structured data

#Python #Javascript #JSON #nested-array-object

Install & run:
$ pip install objectpath $$ objectpath

Star     Follow @adriank

In weather readings find cities where temperature is higher than 25°C and the sky is clear.

The example is based on data from openweathermap.org API. See the JSON file.
$..*[@..temp > 25 and @.clouds.all is 0].name

The root of the document

$ 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.

The current item

@ 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.

Recursive descent

.. finds all objects in the subtree. Here it selects all objects from the readings.

The wildcard

* 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

The selector

[] is an advanaced tool for filtering lists of objects. It can do almost anything! More at selectors reference

Simple operators

ObjectPath supports a vast range of simple operators including boolean, arithmetic, comparison... and so on. The full list of operators is available in the ObjectPath reference.

Object properties

These are properties of objects that will be checked against the expression.

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.

Data discovery

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.
>>> $.*
  "cnt" :15,
  "list" :[{
    "id" :2217362,

Easy yet powerful

Easy to start with and suitable for complex data-discovery jobs.

Support for complex data sets

Allows for working with big nested tree structures. Up to the size of your RAM.

JS & Python

Available in JS and Python.