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
1be3dbf New:Add scripts/export_requirements_txt.sh
56d09bd Chg:Upgrade dependencies
ba5868c Chg:Update GitHub Actions config
944fe7b New:Add caches action
8625aeb New:Upload release built from actions
b882c38 Chg:Use lark-parser to replace sly
dad27f8 Fix,Dev:CI err because of poetry install git dep
1fd8c41 Chg:Replace tab with space in grammar.lark
e1a73a4 Chg:more specific type annotation
9dbbdfb Chg:Upgrade lark to 0.8.1
b62b848 Chg:Rafactoring for reducing non-neccessory code
b84fb93 Fix:Not raise JSONPath undefined function error explicitly
d9ff6f6 Chg:Use type.__new__ to overwrite expr’s find method
3b8d41d Chg:Refactoring for reducing the duplicated code
ce42257 New:Create docs by sphinx
bb31c2c Fix,Dev:lint docs error
b09ec5e New,Dev:Watch related files, build and serve Sphinx documentation automatically.
a078e8f Fix,Dev:Isort error
db56773 New,Dev:Test with doctest by pytest
48ad21c Fix,Dev:shell function not inherits envs of parent process
28a4fc0 Fix,Dev:lint error
a78fdf8 Fix,Dev:Live reload docs error due to .venv/bin/python not setting env-values
2995f46 New,Doc:API reference
d918d80 Chg,Doc:Update quickstarts.rst
f18d92c New:Add .readthedocs.yaml for docs deployment
e6b7576 New,Doc:Translate :py:mod: directive into link
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
Built Distribution
Hashes for jsonpath-extractor-0.2.0a0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b68821fbb34d79fdb8bd4ad35e4fe21f7252861d7967b8cf35ef9256749352b7 |
|
MD5 | f8932fab051e17c2800c56bb21d12967 |
|
BLAKE2b-256 | 7dfa79fbae302592f4bf58eea760487ed93aa34d655b1b07a48c470ccdb27ba9 |
Hashes for jsonpath_extractor-0.2.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff8fce4f70a7255803fe9dcb4ad7d60370ff412a99b5b25ff62abca186aefa3c |
|
MD5 | a16163b2dbb90789d72617ab7ea80d14 |
|
BLAKE2b-256 | f01b84a7376e177933f96b8b76ad74b630136843273aa82d7f66350b4141f59b |