A selector expression for extracting data from JSON.
Project description
A selector expression for extracting data from JSON.
Quickstarts
Installation
Install the stable version from PYPI.
pip install jsonpath-extractor
Or install the latest version from Github.
pip install git+https://github.com/linw1995/jsonpath.git@master
Usage
{
"goods": [
{"price": 100, "category": "Comic book"},
{"price": 200, "category": "magazine"},
{"price": 200, "no category": ""}
],
"targetCategory": "book"
}
How to parse and extract all the comic book data from the above JSON file.
import json
from jsonpath import parse
with open("example.json", "r") as f:
data = json.load(f)
assert parse("$.goods[contains(@.category, $.targetCategory)]").find(
data
) == [{"price": 100, "category": "Comic book"}]
Or use the jsonpath.core module to extract it.
from jsonpath.core import Root, Contains, Self
assert Root().Name("goods").Array(
Contains(Self().Name("category"), Root().Name("targetCategory"))
).find(data) == [{"price": 100, "category": "Comic book"}]
Changelog
v0.2.0-alpha.2
2440951 Fix:Cannot release into PyPI
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
jsonpath-extractor-0.2.0a2.tar.gz
(12.4 kB
view hashes)
Built Distribution
Close
Hashes for jsonpath-extractor-0.2.0a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a19d797541b717f96cbfac7d97bedd62d6b62a6da2b84399801b285a1216330 |
|
MD5 | 9920a8b259abc8b8727f06f8669c7a29 |
|
BLAKE2b-256 | b0eb71371eda7b34c7c5343f894c331de58d328e808e069dc37b1bd80cdfd947 |
Close
Hashes for jsonpath_extractor-0.2.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51ee13ad61e2802f18eef6a69c21d63268bc8c6843f8dd3fe6a5356f55220b6d |
|
MD5 | 0861548b359a427668e77a4d7b127477 |
|
BLAKE2b-256 | bd68cdfa7b457183dc6ee13fdad8dd08ef19fd5dcd0657683b8629e3b46ad170 |