Skip to content

donkomura/rjq

Repository files navigation

rjq

An interactive CLI tool for JSON querying.

Features

  • Interactive TUI: Terminal-based user interface with real-time JSON processing
  • jaq Integration: Uses the powerful jaq library for JSON querying with jq-compatible syntax
  • Syntax Highlighting: Beautiful color-coded JSON output for better readability
  • Scrolling Support: Navigate through large JSON files with Up/Down arrow keys
  • File and Stdin Input: Process JSON from files or pipe data directly
  • Error Handling: Clear error messages for invalid queries or malformed JSON

Installation

From Source

git clone https://github.com/donkomura/rjq.git
cd rjq
cargo build --release

The binary will be available at target/release/rjq.

Usage

Basic Usage

# Process JSON from stdin
echo '{"name": "John", "age": 30}' | rjq

# Use with a file argument
rjq -f data.json

Interactive Mode

Once rjq starts, you can:

  1. Enter jq queries: Type any jq-compatible query in the input field
  2. Navigate results: Use / arrow keys to scroll through large JSON outputs
  3. Clear input: Press Ctrl+U to clear the current query
  4. Exit: Press Ctrl+C or q to quit

Example Queries

# Identity (show all data)
.

# Get a specific field
.name

# Filter arrays
.users[] | select(.age > 25)

# Map over arrays
.items | map(.price * 1.1)

# Get object keys
keys

# Get array length
.users | length

Command Line Options

Usage: rjq [OPTIONS] [JSON_FILE]

Arguments:
  [JSON_FILE]  JSON file to process (optional, will read from stdin if not provided)

Options:
  -f, --file <FILE>  JSON file to process
  -h, --help         Print help
  -V, --version      Print version

Architecture

  • Backend: jaq library for JSON processing
  • Frontend: ratatui for terminal UI
  • Syntax Highlighting: Custom tokenizer with real-time color coding
  • Event Handling: Crossterm for keyboard input management

Examples

Processing a simple JSON file

{
  "users": [
    {"name": "Alice", "age": 30, "active": true},
    {"name": "Bob", "age": 25, "active": false}
  ]
}

Queries you can try:

  • .users[0].name"Alice"
  • .users[] | select(.active){"name": "Alice", "age": 30, "active": true}
  • .users | map(.age)[30, 25]

Development

Requirements

  • Rust 1.70 or later
  • Cargo

Building

cargo build

Testing

cargo test

Linting

cargo clippy
cargo fmt

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

An interactive CLI tool for JSON querying.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages