Skip to main content

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

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
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jsonpath-extractor, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size jsonpath_extractor-0.1.0-py3-none-any.whl (9.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size jsonpath-extractor-0.1.0.tar.gz (9.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page