A Python toolkit for parsing JSON document
Project description
Python JsonPath
A Python tool that parses JSON documents using JsonPath
Inspired by: https://github.com/json-path/JsonPath
Quick Start
install it using the pip command
pip install pyjsonpath
Then:
>>> from pyjsonpath import JsonPath
>>> obj = {"name": "jsonpath"}
>>> JsonPath(obj, "$.name").load()
['jsonpath']
>>>
JsonPath Syntax
- General Operators
operators | description |
---|---|
$ | The root element to query. This starts all path expressions. |
@ | The current node being processed by a filter predicate. |
* | Wildcard. Available anywhere a name or numeric are required. |
.. | Deep scan. Available anywhere a name is required. |
. | Dot-notated child |
['<name>' (, '<name>')] | Bracket-notated child or children |
[<number> (, <number>)] | Array index or indexes |
[start:end] | Array slice operator |
[?(<expression>)] | Filter expression. Expression must evaluate to a boolean value. |
- Filter Operators
operators | description |
---|---|
== | left is equal to right (note that 1 is not equal to '1') |
!= | left is not equal to right |
< | left is less than right |
<= | left is less or equal to right |
> | left is greater than right |
>= | left is greater than or equal to right |
=~ | left matches regular expression [?(@.name =~ /foo.*?/i)] |
in | left exists in right [?(@.size in ['S', 'M'])] |
nin | left does not exists in right |
subsetof | left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])] |
anyof | left has an intersection with right [?(@.sizes anyof ['M', 'L'])] |
noneof | left has no intersection with right [?(@.sizes noneof ['M', 'L'])] |
size | size of left (array or string) should match right |
empty | left (array or string) should be empty |
- Functions
operators | description |
---|---|
min() | Provides the min value of an array of numbers |
max() | Provides the max value of an array of numbers |
avg() | Provides the average value of an array of numbers |
stddev() | Provides the standard deviation value of an array of numbers |
length() | Provides the length of an array |
sum() | Provides the sum value of an array of numbers |
keys() | Provides the property keys (An alternative for terminal tilde ~) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyjsonpath-1.2.1.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for pyjsonpath-1.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ef8d4b133e83ccdeffb60a2a46a20bc10de2348c1b9b74f0db2b7d583a28167 |
|
MD5 | 88686a6b05aa4e2fac1dc11ba8dffac8 |
|
BLAKE2b-256 | 6b0c29f59173e465e1bf902c06ce21c112862d8a811a3efb5ecad8a0b984293f |