Metadata-Version: 2.1
Name: jsonpath-extractor
Version: 0.1.0
Summary: A selector expression for extracting data from JSON.
Home-page: https://github.com/linw1995/jsonpath
License: MIT
Author: 林玮
Author-email: linw1995@icloud.com
Requires-Python: >=3.7,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Provides-Extra: lint
Provides-Extra: test
Requires-Dist: black (>=19.3b0,<20.0); extra == "lint"
Requires-Dist: flake8 (>=3.7.8,<4.0.0); extra == "lint"
Requires-Dist: flake8-bugbear (>=19.8,<20.0); extra == "lint"
Requires-Dist: isort (>=4.3.21,<5.0.0); extra == "lint"
Requires-Dist: mypy (>=0.750,<0.751); extra == "lint"
Requires-Dist: pytest (>=5.2.0,<6.0.0); extra == "lint" or extra == "test"
Requires-Dist: pytest-cov (>=2.7.1,<3.0.0); extra == "test"
Requires-Dist: sly (>=0.3.0,<0.4.0)
Requires-Dist: typing_extensions (>=3.7,<4.0)
Project-URL: Repository, https://github.com/linw1995/jsonpath
Description-Content-Type: text/x-rst

========
JSONPATH
========

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:: python3

    import json

    from jsonpath import parse, Root, Contains, Self

    data = json.loads(
        """
        {
            "goods": [
                {"price": 100, "category": "Comic book"},
                {"price": 200, "category": "magazine"},
                {"price": 200, "no category": ""}
            ],
            "targetCategory": "book"
        }
    """
    )
    expect = [{"price": 100, "category": "Comic book"}]

    assert parse("$.goods[contains(@.category, $.targetCategory)]").find(data) == expect

    assert (
        Root()
        .Name("goods")
        .Array(Contains(Self().Name("category"), Root().Name("targetCategory")))
        .find(data)
        == expect
    )

