Skip to main content

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 using uv (recommended):

uv tool install jpq
# alternatively (using pip/pipx):
# pipx install jpq
# pip install --user jpq

From source, after cloning:

uv tool install .

By building locally:

uv build
uv tool install ./dist/jpq-*.whl

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 '{"a": [{"b": 2}]}' | jpq 'this.a[0].b'  # 2

$ echo '[{"status":"ok"},{"status":"error"},{"status":"ok"}]' | jpq 'collections.Counter(el["status"] for el in this)'  # {"ok": 2, "error": 1}

Note that you can access dict keys as attributes, e.g. this.name instead of this["name"].

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 '
{
"now": (now:=datetime.datetime.now(tz=datetime.UTC)),
"stars": this["stargazers_count"],
"last_pushed_seconds_ago": (
    now - datetime.datetime.fromisoformat(this["pushed_at"])
).total_seconds(),
}'
{
  "now": "2026-05-13T15:05:11.746397+00:00",
  "stars": 72668,
  "last_pushed_seconds_ago": 566.746397
}

Note how the walrus operator (:=) is used to assign now and use it in the expression and how it is serialized to JSON via datetime fallback.

See more examples in the blog post about jpq.

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.2.1.tar.gz (39.2 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.2.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jpq-0.2.1.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.1.tar.gz
Algorithm Hash digest
SHA256 f32815ad05d8cdff3328d5328ef06ad5f85e68b634f014df07d6fb98e8bd24fb
MD5 e0c676df4099af407f3f4d926f0574d1
BLAKE2b-256 b4ae9762251c4ad6b23c6a65861c73d9dadc11376e34ab610fa676a8a9860713

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jpq-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 370462fd958daf91b457d151b888cc876a016d5caa4b0ff8a308e4775accbab4
MD5 aa1ccbfa74442e6f5e333d3eda824bd6
BLAKE2b-256 e1c442a528501544e2f7a7d2c87efc898a2d097bc386fbcf9f4a1036b18eddaf

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Supported by

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