Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

JSONPath CLI

A lightweight command-line tool for querying JSON files using JSONPath expressions.

Features

  • 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

Installation

pip install -r requirements.txt

Usage

Basic query

python jsonpath_cli.py data.json "$.users[*].name"

Query from stdin

cat data.json | python jsonpath_cli.py - "$.users[?(@.age > 25)]"

Output formats

# 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

JSONPath Syntax Examples

  • $.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

Examples

Sample data.json

{
"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"}
]
}

Queries

# 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" --raw

License

MIT License

About

Lightweight CLI tool for querying JSON files using JSONPath expressions with colored output

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages