Skip to main content

jq-style JSON filtering with Python expressions.

Project description

jpq

jq-style JSON filtering, but with Python expressions.

The parsed stdin JSON is bound to this; the value of the expression is printed as JSON.

Install

From PyPI:

uv tool install jpq
# or: pipx install jpq
# or: pip install --user jpq

From source, after cloning:

uv tool install .

Or run straight from the checkout without (re)installing:

$ echo '[1, 2]' | uv run main.py 'this[0]'
1

Usage

$ echo '{"name":"alice","age":30}' | jpq 'this["name"]'
"alice"

$ echo '[1,2,3,4,5]' | jpq 'statistics.mean(this)'
3

$ echo '[{"k":"a"},{"k":"b"},{"k":"a"}]' | jpq 'collections.Counter(el["k"] for el in this)'
{"a": 2, "b": 1}

Pre-imported in the eval namespace: re, collections, itertools, statistics, math, datetime, plus all builtins.

Run jpq --help for more.

Advanced examples

Pipe an API response through a multi-line expression to reshape it:

$ curl -s https://api.github.com/repos/python/cpython | jpq '
{
"stars": this["stargazers_count"],
"last_pushed_seconds_ago": (
    datetime.datetime.now(tz=datetime.UTC)
    - datetime.datetime.fromisoformat(this["pushed_at"])
).total_seconds()
}'
{"stars": 72644, "last_pushed_seconds_ago": 2168.664175}

Read environment variables:

export PASS=secret123
echo '{"url": "postgres://user:pass@host:port/db"}' | jpq 'this["url"].replace("pass", env("PASS"))'
# "postgres://user:secret123@host:port/db"

Here env("PASS") is equivalent to os.environ["PASS"] (see helpers.py).

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

jpq-0.1.3.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jpq-0.1.3-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file jpq-0.1.3.tar.gz.

File metadata

  • Download URL: jpq-0.1.3.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jpq-0.1.3.tar.gz
Algorithm Hash digest
SHA256 acbfa1d23d21953b81df9f9e2a007686f9c496cab5bbef16a2a1b2acee69c275
MD5 b6ecd78718c9593fd3f583d18f66fdb4
BLAKE2b-256 ddbcec06c5dc7249ea04a2003cd2314aa0cde9cb45eda3541df098ab3d5f1068

See more details on using hashes here.

File details

Details for the file jpq-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: jpq-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jpq-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ee3e760b3e5ac03826bd361f216d49ea0578932d92fe524fb3e908b38e0aff58
MD5 1b228db75cd0da1dd76cc1a946ceae45
BLAKE2b-256 82bbf05b82987a47171fc216d4f1b69b1a50ccd8e1430ae45bc4cebc8cceeea8

See more details on using hashes here.

Supported by

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