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 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 '[{"status":"ok"},{"status":"error"},{"status":"ok"}]' | jpq 'collections.Counter(el["status"] for el in this)' # {"ok": 2, "error": 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 '
{
"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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jpq-0.1.5.tar.gz.
File metadata
- Download URL: jpq-0.1.5.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53cbcdeeb58e65237c8fb8b9598acefecac049026cf62976b8f74bd109825505
|
|
| MD5 |
0900764bcd663432329b4b8c4e9234e7
|
|
| BLAKE2b-256 |
9c54502e201262cb73026056e148841f123967fe960cd0f134ec2c2aeb394465
|
File details
Details for the file jpq-0.1.5-py3-none-any.whl.
File metadata
- Download URL: jpq-0.1.5-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f849f28aecf70a669b7829bc7a7ee4e9a954f09e8279e3aa39c4a14a8f17f35
|
|
| MD5 |
973833f3c0c590475c0a151e9d1c3682
|
|
| BLAKE2b-256 |
856d52c26eb833775967f9588bc167971ff9a21bab8326768f442c219036b3c8
|