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.0.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.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jpq-0.2.0.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.0.tar.gz
Algorithm Hash digest
SHA256 8fca5dae173ab19e4e773646578f2715da9e771f33318c94f9320a09f1be489e
MD5 6d15ac96a2740bf4afb8f2a5a37773e4
BLAKE2b-256 ec085a40285d0f8b7350af5f6574290d24522083bf19c545b191477dd8edea83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jpq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 515796a67b90249af6cdb0030612751b6a15d730b3d7af808e55c6d5f904bdea
MD5 e7a52cbd69631ad7acae0ec57b81cd37
BLAKE2b-256 c3880fdb34aea63e7f6c0cc2b3c8381b36444f865ac234acd535e09245ad68d0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

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