# jarq - Interactive JSON Query Tool

A jq-like interactive JSON viewer and filter tool built with Rust and Ratatui.

## Build & Test

```bash
cargo build --release
cargo test
cargo fmt
cargo clippy -- -D warnings
```

## Architecture

### Core Components

- **`src/main.rs`**: Entry point, argument parsing, TUI loop
- **`src/app.rs`**: Application state and input handling
- **`src/ui.rs`**: Rendering (virtualized for large files)
- **`src/filter/`**: jq-style filter parsing and evaluation
- **`src/worker.rs`**: Background thread for filter evaluation with pipe caching
- **`src/loader.rs`**: Async file loading thread

### Performance Optimizations

**Async Loading**: Files load in a background thread while UI shows "Loading..." immediately.

**Virtualized Rendering**: Only visible lines (~50) are rendered each frame. Large files (1GB+) don't pre-render millions of lines into memory.

**Pipe Caching**: When extending a filter at a pipe boundary (e.g., `.[] | .name` → `.[] | .name | unique`), only the new suffix is evaluated against cached intermediate results.

**Evaluation Control**:
- `Ctrl-P`: Pause/resume auto-evaluation - lets you type a complete filter without triggering intermediate evaluations (syntax is still validated immediately)
- `Ctrl-C` (in filter edit mode): Cancel current evaluation - stops waiting for result (worker continues but result is ignored)
- `Ctrl-H`: Open help (works in both navigation and filter edit modes)

### Memory Considerations

`serde_json::Value` uses ~3-5x the file size in memory. A 128MB file becomes ~500MB-1GB in RAM. This is inherent to serde_json's representation. Further optimization would require:
- A different JSON library (e.g., simd-json with tape-based storage)
- Streaming/memory-mapped parsing

## Code Style

- Run `cargo fmt` after making changes
- Run `cargo clippy -- -D warnings` before committing
- Avoid pre-1.0 compatibility concerns - rip out unused code
- Keep rendering virtualized - never store all lines in memory
