O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using JSONPath in your Python application

There are several implementations of JSONPath for Python, too. The best is jsonpath-rw library, which provides language extensions so that paths are first-class language objects.

Getting ready

You'll need to install the jsonpath-rw library using pip:

pip install jsonpath-rw

Also, of course, you will need to include the necessary bits of the library when using them:

fromjsonpath_rw import jsonpath, parse

How to do it…

Here's a simple example using our store contents in the introduction stored in the variable object:

>>> object = { … }

>>>path = parse('$..title') 

>>> [match.value for match in path.find(object)]
['Sayings of the Century','Sword of Honour', 'Moby Dick', 'The Lord of the Rings']

How it works…

Processing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required