GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - linw1995/jsonpath: A query expression for extracting data from JSON.

BranchesTags
Open more actions menu

Latest commit

 

History

265 Commits
265 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
jsonpath
jsonpath
 
 
scripts
scripts
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
.readthedocs.yaml
.readthedocs.yaml
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.rst
README.rst
 
 
README.template.rst
README.template.rst
 
 
conftest.py
conftest.py
 
 
default.nix
default.nix
 
 
example.json
example.json
 
 
flake.lock
flake.lock
 
 
flake.nix
flake.nix
 
 
jsonpath_build.py
jsonpath_build.py
 
 
noxfile.py
noxfile.py
 
 
pdm.lock
pdm.lock
 
 
pyproject.toml
pyproject.toml
 
 
setup.cfg
setup.cfg
 
 

Repository files navigation

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.

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").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.

jp -f example.json "$.goods[contains(@.category, $.targetCategory)]"

Or pass content by pipeline.

cat example.json | jp "$.goods[contains(@.category, $.targetCategory)]"

The output of the above commands.

[
  {
    "price": 100,
    "category": "Comic book"
  }
]

Changelog

v0.9.1

Build

  • Remove support for Python 3.8

Contributing

Environment Setup

Clone the source codes from Github.

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.

make init
make PYTHON=3.8 init  # for specific python version

Linting

Use pre-commit for installing linters to ensure a good code style.

make pre-commit

Run linters. Some linters run via CLI nox, so make sure you install it.

make check-all

Testing

Run quick tests.

make

Run quick tests with verbose.

make vtest

Run tests with coverage. Testing in multiple Python environments is powered by CLI nox.

make cov

Documentation

Run serving documents with live-reloading.

make serve-docs

About

A query expression for extracting data from JSON.

jsonpath.rtfd.io/en/latest/

Topics

clidata-extractiondata-extractorjsonpath

Resources

Readme
MIT license

Code of conduct

Code of conduct
Activity

Stars

41 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.