========
JSONPATH
========
|license| |Pypi Status| |Python version| |Package version| |PyPI - Downloads|
|GitHub last commit| |Code style: black| |Build Status| |codecov| |PDM managed|
A selector expression for extracting data from JSON.
Quickstarts
<<<<<<<<<<<
Installation
~~~~~~~~~~~~
Install the stable version from PYPI.
.. code-block:: shell
pip install jsonpath-extractor
Or install the latest version from Github.
.. code-block:: shell
pip install git+https://github.com/linw1995/jsonpath.git@master
Usage
~~~~~
.. code-block:: json
{
"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.
.. code-block:: python3
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 <https://jsonpath.readthedocs.io/en/latest/api_core.html>`_ module to extract it.
.. code-block:: python3
from jsonpath.core import Root, Contains, Self
assert Root().Name("goods").Predicate(
Contains(Self().Name("category"), Root().Name("targetCategory"))
).find(data) == [{"price": 100, "category": "Comic book"}]
Usage via CLI
~~~~~~~~~~~~~
The faster way to extract by using CLI.
.. code-block:: shell
jp -f example.json "$.goods[contains(@.category, $.targetCategory)]"
Or pass content by pipeline.
.. code-block:: shell
cat example.json | jp "$.goods[contains(@.category, $.targetCategory)]"
The output of the above commands.
.. code-block:: json
[
{
"price": 100,
"category": "Comic book"
}
]
Changelog
<<<<<<<<<
v0.9.0
~~~~~~
Build
*****
- Remove support for Python 3.7
Contributing
<<<<<<<<<<<<
Environment Setup
~~~~~~~~~~~~~~~~~
Clone the source codes from Github.
.. code-block:: shell
git clone https://github.com/linw1995/jsonpath.git
cd jsonpath
Setup the development environment.
Please make sure you install the pdm_,
pre-commit_ and nox_ CLIs in your environment.
.. code-block:: shell
make init
make PYTHON=3.8 init # for specific python version
Linting
~~~~~~~
Use pre-commit_ for installing linters to ensure a good code style.
.. code-block:: shell
make pre-commit
Run linters. Some linters run via CLI nox_, so make sure you install it.
.. code-block:: shell
make check-all
Testing
~~~~~~~
Run quick tests.
.. code-block:: shell
make
Run quick tests with verbose.
.. code-block:: shell
make vtest
Run tests with coverage.
Testing in multiple Python environments is powered by CLI nox_.
.. code-block:: shell
make cov
Documentation
~~~~~~~~~~~~~
Run serving documents with live-reloading.
.. code-block:: shell
make serve-docs
.. _pdm: https://github.com/pdm-project/pdm
.. _pre-commit: https://pre-commit.com/
.. _nox: https://nox.thea.codes/en/stable/
.. |license| image:: https://img.shields.io/github/license/linw1995/jsonpath.svg
:target: https://github.com/linw1995/jsonpath/blob/master/LICENSE
.. |Pypi Status| image:: https://img.shields.io/pypi/status/jsonpath-extractor.svg
:target: https://pypi.org/project/jsonpath-extractor
.. |Python version| image:: https://img.shields.io/pypi/pyversions/jsonpath-extractor.svg
:target: https://pypi.org/project/jsonpath-extractor
.. |Package version| image:: https://img.shields.io/pypi/v/jsonpath-extractor.svg
:target: https://pypi.org/project/jsonpath-extractor
.. |PyPI - Downloads| image:: https://img.shields.io/pypi/dm/jsonpath-extractor.svg
:target: https://pypi.org/project/jsonpath-extractor
.. |GitHub last commit| image:: https://img.shields.io/github/last-commit/linw1995/jsonpath.svg
:target: https://github.com/linw1995/jsonpath
.. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
.. |Build Status| image:: https://github.com/linw1995/jsonpath/workflows/Lint&Test/badge.svg
:target: https://github.com/linw1995/jsonpath/actions?query=workflow%3ALint%26Test
.. |codecov| image:: https://codecov.io/gh/linw1995/jsonpath/branch/master/graph/badge.svg
:target: https://codecov.io/gh/linw1995/jsonpath
.. |PDM managed| image:: https://img.shields.io/badge/pdm-managed-blueviolet
:target: https://pdm.fming.dev
Raw data
{
"_id": null,
"home_page": "",
"name": "jsonpath-extractor",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "data-extractor,data-extraction,jsonpath,json",
"author": "",
"author_email": "\u6797\u73ae (Jade Lin) <linw1995@icloud.com>",
"download_url": "https://files.pythonhosted.org/packages/3f/f2/547953c67690818d7e02894059bcd782f1631e125daafdec553c9cf2f4ef/jsonpath-extractor-0.9.0.tar.gz",
"platform": null,
"description": "========\nJSONPATH\n========\n\n|license| |Pypi Status| |Python version| |Package version| |PyPI - Downloads|\n|GitHub last commit| |Code style: black| |Build Status| |codecov| |PDM managed|\n\nA selector expression for extracting data from JSON.\n\nQuickstarts\n<<<<<<<<<<<\n\n\nInstallation\n~~~~~~~~~~~~\n\nInstall the stable version from PYPI.\n\n.. code-block:: shell\n\n pip install jsonpath-extractor\n\nOr install the latest version from Github.\n\n.. code-block:: shell\n\n pip install git+https://github.com/linw1995/jsonpath.git@master\n\nUsage\n~~~~~\n\n.. code-block:: json\n\n {\n \"goods\": [\n {\"price\": 100, \"category\": \"Comic book\"},\n {\"price\": 200, \"category\": \"magazine\"},\n {\"price\": 200, \"no category\": \"\"}\n ],\n \"targetCategory\": \"book\"\n }\n\n\nHow to parse and extract all the comic book data from the above JSON file.\n\n.. code-block:: python3\n\n import json\n\n from jsonpath import parse\n\n with open(\"example.json\", \"r\") as f:\n data = json.load(f)\n\n assert parse(\"$.goods[contains(@.category, $.targetCategory)]\").find(data) == [\n {\"price\": 100, \"category\": \"Comic book\"}\n ]\n\nOr use the `jsonpath.core <https://jsonpath.readthedocs.io/en/latest/api_core.html>`_ module to extract it.\n\n.. code-block:: python3\n\n from jsonpath.core import Root, Contains, Self\n\n assert Root().Name(\"goods\").Predicate(\n Contains(Self().Name(\"category\"), Root().Name(\"targetCategory\"))\n ).find(data) == [{\"price\": 100, \"category\": \"Comic book\"}]\n\n\nUsage via CLI\n~~~~~~~~~~~~~\n\nThe faster way to extract by using CLI.\n\n.. code-block:: shell\n\n jp -f example.json \"$.goods[contains(@.category, $.targetCategory)]\"\n\nOr pass content by pipeline.\n\n.. code-block:: shell\n\n cat example.json | jp \"$.goods[contains(@.category, $.targetCategory)]\"\n\nThe output of the above commands.\n\n.. code-block:: json\n\n [\n {\n \"price\": 100,\n \"category\": \"Comic book\"\n }\n ]\n\nChangelog\n<<<<<<<<<\n\nv0.9.0\n~~~~~~\n\nBuild\n*****\n\n- Remove support for Python 3.7\n\n\nContributing\n<<<<<<<<<<<<\n\n\nEnvironment Setup\n~~~~~~~~~~~~~~~~~\n\nClone the source codes from Github.\n\n.. code-block:: shell\n\n git clone https://github.com/linw1995/jsonpath.git\n cd jsonpath\n\nSetup the development environment.\nPlease make sure you install the pdm_,\npre-commit_ and nox_ CLIs in your environment.\n\n.. code-block:: shell\n\n make init\n make PYTHON=3.8 init # for specific python version\n\nLinting\n~~~~~~~\n\nUse pre-commit_ for installing linters to ensure a good code style.\n\n.. code-block:: shell\n\n make pre-commit\n\nRun linters. Some linters run via CLI nox_, so make sure you install it.\n\n.. code-block:: shell\n\n make check-all\n\nTesting\n~~~~~~~\n\nRun quick tests.\n\n.. code-block:: shell\n\n make\n\nRun quick tests with verbose.\n\n.. code-block:: shell\n\n make vtest\n\nRun tests with coverage.\nTesting in multiple Python environments is powered by CLI nox_.\n\n.. code-block:: shell\n\n make cov\n\nDocumentation\n~~~~~~~~~~~~~\n\nRun serving documents with live-reloading.\n\n.. code-block:: shell\n\n make serve-docs\n\n.. _pdm: https://github.com/pdm-project/pdm\n.. _pre-commit: https://pre-commit.com/\n.. _nox: https://nox.thea.codes/en/stable/\n\n.. |license| image:: https://img.shields.io/github/license/linw1995/jsonpath.svg\n :target: https://github.com/linw1995/jsonpath/blob/master/LICENSE\n\n.. |Pypi Status| image:: https://img.shields.io/pypi/status/jsonpath-extractor.svg\n :target: https://pypi.org/project/jsonpath-extractor\n\n.. |Python version| image:: https://img.shields.io/pypi/pyversions/jsonpath-extractor.svg\n :target: https://pypi.org/project/jsonpath-extractor\n\n.. |Package version| image:: https://img.shields.io/pypi/v/jsonpath-extractor.svg\n :target: https://pypi.org/project/jsonpath-extractor\n\n.. |PyPI - Downloads| image:: https://img.shields.io/pypi/dm/jsonpath-extractor.svg\n :target: https://pypi.org/project/jsonpath-extractor\n\n.. |GitHub last commit| image:: https://img.shields.io/github/last-commit/linw1995/jsonpath.svg\n :target: https://github.com/linw1995/jsonpath\n\n.. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/ambv/black\n\n.. |Build Status| image:: https://github.com/linw1995/jsonpath/workflows/Lint&Test/badge.svg\n :target: https://github.com/linw1995/jsonpath/actions?query=workflow%3ALint%26Test\n\n.. |codecov| image:: https://codecov.io/gh/linw1995/jsonpath/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/linw1995/jsonpath\n\n.. |PDM managed| image:: https://img.shields.io/badge/pdm-managed-blueviolet\n :target: https://pdm.fming.dev\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A selector expression for extracting data from JSON.",
"version": "0.9.0",
"project_urls": {
"documentation": "https://jsonpath.rtfd.io/en/latest/",
"homepage": "https://github.com/linw1995/jsonpath",
"repository": "https://github.com/linw1995/jsonpath"
},
"split_keywords": [
"data-extractor",
"data-extraction",
"jsonpath",
"json"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c1ad6e0d352d0c5f3fc5d8ae8d0a7abb3b8030bea228d00d3cb91082b9a5bb9a",
"md5": "866a4077b0468e1d03da0d48803e095f",
"sha256": "59c462bb660cfb3b20b85a30788e48d65b9149ef75a37b4aaaf3a5c9d7375c92"
},
"downloads": -1,
"filename": "jsonpath_extractor-0.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "866a4077b0468e1d03da0d48803e095f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 43872,
"upload_time": "2023-07-15T02:50:06",
"upload_time_iso_8601": "2023-07-15T02:50:06.212384Z",
"url": "https://files.pythonhosted.org/packages/c1/ad/6e0d352d0c5f3fc5d8ae8d0a7abb3b8030bea228d00d3cb91082b9a5bb9a/jsonpath_extractor-0.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3ff2547953c67690818d7e02894059bcd782f1631e125daafdec553c9cf2f4ef",
"md5": "a93106918268130ea81c72278b34df78",
"sha256": "1710e5cf65b6d3fde3cbbf5512f763a5177351932abe8eb27fb8081f4818bae4"
},
"downloads": -1,
"filename": "jsonpath-extractor-0.9.0.tar.gz",
"has_sig": false,
"md5_digest": "a93106918268130ea81c72278b34df78",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 47007,
"upload_time": "2023-07-15T02:50:08",
"upload_time_iso_8601": "2023-07-15T02:50:08.137657Z",
"url": "https://files.pythonhosted.org/packages/3f/f2/547953c67690818d7e02894059bcd782f1631e125daafdec553c9cf2f4ef/jsonpath-extractor-0.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-15 02:50:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "linw1995",
"github_project": "jsonpath",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "jsonpath-extractor"
}