A lightweight command-line tool for querying JSON files using JSONPath expressions.
- Query JSON files with JSONPath syntax
- Pretty-print output with color highlighting
- Support for stdin input
- Multiple output formats (JSON, raw values, compact)
- Filter and extract nested data easily
pip install -r requirements.txtpython jsonpath_cli.py data.json "$.users[*].name"cat data.json | python jsonpath_cli.py - "$.users[?(@.age > 25)]"# Pretty JSON (default)
python jsonpath_cli.py data.json "$.users[0]"
# Compact JSON
python jsonpath_cli.py data.json "$.users[0]" --compact
# Raw values only
python jsonpath_cli.py data.json "$.users[*].email" --raw$.store.book[*].author- All book authors$..author- All authors (recursive)$.store.*- All things in store$.store..price- All prices$..book[2]- Third book$..book[-1]- Last book$..book[0,1]- First two books$..book[:2]- First two books$..book[?(@.price < 10)]- Books cheaper than 10$..book[?(@.isbn)]- Books with ISBN
{
"users": [
{"name": "Alice", "age": 30, "email": "alice@example.com"},
{"name": "Bob", "age": 25, "email": "bob@example.com"},
{"name": "Charlie", "age": 35, "email": "charlie@example.com"}
]
}# Get all names
python jsonpath_cli.py data.json "$.users[*].name"
# Filter users over 25
python jsonpath_cli.py data.json "$.users[?(@.age > 25)]"
# Get first user's email
python jsonpath_cli.py data.json "$.users[0].email" --rawMIT License