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
Chg:Use lark-parser to replace sly
New:Create docs by sphinx
New,Dev:Watch related files, build and serve Sphinx documentation automatically.
New,Dev:Test with doctest by pytest
New:Add .readthedocs.yaml for docs deployment
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.0.tar.gz
(12.6 kB
view hashes)
Built Distribution
Close
Hashes for jsonpath_extractor-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52753975e37d9b0c247fbdf86219bb810bb18cde1583207704e12fc7991c2856 |
|
MD5 | 1389fa21ec94d3dbf49df56172d87e90 |
|
BLAKE2b-256 | d4b1c796ac4bf0d4d1de7fa8ae5f231bd6cb754b7e535873d732b71239182444 |