Skip to main content

A selector expression for extracting data from JSON.

Project description

license Pypi Status Python version Package version PyPI - Downloads GitHub last commit Code style: black Build Status codecov

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

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
)

Changelog

  • 35f0960 New:Add release actions for pypi and gh-release

  • ce022b6 New:Add codecov for code coverage report

  • 7f4fe3c Fix:The reduce/reduce conflicts

  • 258b0fa Fix:The shift/reduce conflicts

  • 95f088d New:Add Github Actions for CI

Project details


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.1.1.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

jsonpath_extractor-0.1.1-py3-none-any.whl (10.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page