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 ...
Get JavaScript JSON Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.