# π¨ jsonfizz
[](https://crates.io/crates/jsonfizz)
[](https://github.com/lance0/jsonfizz)
[](https://www.rust-lang.org)
Fast, zero fuss JSON formatter and pretty printer for the terminal. β¨
## β¨ Features
- π **Blazing fast** - Written in Rust
- π¨ **Beautiful themes** - 11 color schemes including anime themes
- π **JSON path queries** - Extract specific values
- π **Depth limiting** - Handle large JSON gracefully
- π― **Multiple inputs** - Files, stdin, or pipes
- βοΈ **Configurable** - TOML config file support
- π **Format conversion** - JSON β YAML β TOML, CSV output
- π **CSV friendly** - Read CSV and convert to JSON
- π **Multiple formats** - JSON and YAML output
- β
**Schema checks** - Optional JSON Schema validation
- π **Shell completion** - Auto-completion for bash/zsh/fish
- π **Performance benchmarks** - Built-in performance testing
- π **Progress indicators** - Feedback for large file processing
## π¦ Installation
```bash
cargo install jsonfizz
```
## π Library Usage
You can use `jsonfizz` as a Rust library in your own projects:
```toml
[dependencies]
jsonfizz = "0.2.0"
serde_json = "1.0"
```
```rust
use jsonfizz::{config::Config, theme::Theme, formatter::format_value};
use serde_json::json;
fn main() {
let value = json!({"name": "jsonfizz", "awesome": true});
// Configure formatting options
let config = Config {
indent: 4,
theme: "ocean".to_string(),
..Config::default()
};
// Initialize theme
let theme = Theme::new(&config.theme, false).unwrap();
// Format the value
let formatted = format_value(&value, &config, &theme, 0).unwrap();
println!("{}", formatted);
}
```
## π Usage
### Basic formatting
```bash
# From API
# From file
jsonfizz data.json
# From stdin
### Advanced features
```bash
# Watch file for changes and reformat on the fly
jsonfizz data.json --watch
# Extract specific values with JSON path
jsonfizz response.json --get data.items[0].name
# Limit depth for large files
# Compact output
jsonfizz data.json --compact
# Custom indentation
jsonfizz data.json --indent 4
# Sort object keys
jsonfizz data.json --sort-keys
# Format conversion (JSON β YAML β TOML β CSV)
# Read TOML, output as JSON
jsonfizz config.toml --input-format toml --format json
# Read YAML, output as TOML
# Convert JSON array to CSV
# Read CSV and output JSON
jsonfizz data.csv --input-format csv --format json
# Validate against a JSON Schema
jsonfizz data.json --schema schema.json
# Control color output
jsonfizz data.json --color never # Never use colors
jsonfizz data.json --color always # Always use colors
jsonfizz data.json --color auto # Auto-detect (default)
# Read JSON, output as YAML
jsonfizz data.json --format yaml
# Read JSON, output as TOML
jsonfizz data.json --format toml
# Run performance benchmarks
jsonfizz --benchmark
```
### Color themes
```bash
# Rainbow theme π
jsonfizz data.json --theme rainbow
# Ocean theme π
jsonfizz data.json --theme ocean
# Forest theme π²
jsonfizz data.json --theme forest
# Pastel theme π¨
jsonfizz data.json --theme pastel
# Anime themes πΈπ€ποΈποΈ
jsonfizz data.json --theme sakura
jsonfizz data.json --theme cyberpunk
jsonfizz data.json --theme ghibli
jsonfizz data.json --theme evangelion
# Generate shell completions
jsonfizz --generate-completion bash > ~/.bash_completion.d/jsonfizz
jsonfizz --generate-completion zsh > ~/.zsh/_jsonfizz
jsonfizz --generate-completion fish > ~/.config/fish/completions/jsonfizz.fish
```
## βοΈ Configuration
Create `~/.config/jsonfizz/config.toml` or `~/.jsonfizz.toml` to set persistent defaults.
**Full Example:**
```toml
# Indentation size (spaces)
indent = 2
# Sort keys alphabetically (true/false)
sort_keys = true
# Default color theme
theme = "ocean"
# Default output format (json, yaml, toml, csv)
format = "json"
# Max depth to recurse (0 = unlimited)
max_depth = 0
# Max string length before truncation (0 = unlimited)
max_string_length = 0
# Optional: Path to a default JSON schema for validation
# schema = "/path/to/schema.json"
```
CLI flags override config.
## π JSON Path Syntax
The `--get` flag supports a simple dot-notation syntax for extracting values:
- `key`: Access a property of an object.
- `array[index]`: Access an element of an array.
- `data.items[0].name`: Nested access.
**Examples:**
- `users[0].id`
- `config.server.port`
- `rows[5]`
## β
Schema Validation
Validate your JSON against a standard [JSON Schema](https://json-schema.org/).
```bash
jsonfizz data.json --schema schema.json
```
If validation fails, `jsonfizz` will print a clear error message indicating the location of the violation and exit with code 1.
## β Troubleshooting
**"Error: UTF-8"**
`jsonfizz` currently only supports valid UTF-8 input. Ensure your files are encoded correctly.
**"Watch limit reached"**
If using `--watch` on Linux, you might hit the system's file watcher limit. Increase it with:
`sysctl fs.inotify.max_user_watches=524288`
## π¨ Themes
| `default` | Bright, balanced colors | Keys: π‘ Strings: π’ Numbers: π΅ |
| `solarized` | Muted, eye-friendly | Keys: π‘ Strings: π’ Numbers: π΅ |
| `mono` | No colors | Plain text |
| `rainbow` π | Vibrant rainbow | Keys: π΄ Strings: π’ Numbers: π‘ |
| `ocean` π | Cool blue tones | Keys: π΅ Strings: π΅ Numbers: π΅ |
| `forest` π² | Nature greens | Keys: π’ Strings: π’ Numbers: π‘ |
| `pastel` π¨ | Soft pastels | Keys: π©· Strings: π©· Numbers: π©· |
| `sakura` πΈ | Anime pink | Keys: π©· Strings: π΄ Numbers: π΅ |
| `cyberpunk` π€ | Neon cyber | Keys: π©· Strings: π’ Numbers: π΅ |
| `ghibli` ποΈ | Studio Ghibli | Keys: π’ Strings: π‘ Numbers: π΅ |
| `evangelion` ποΈ | Purple & teal | Keys: π©· Strings: π΅ Numbers: π΅ |
## π Options
```
Usage: jsonfizz [OPTIONS] [FILE]...
Arguments:
[FILE]... Input files (use - for stdin)
Options:
-i, --indent <INDENT> [default: 2]
--sort-keys
-c, --compact
--max-depth <MAX_DEPTH>
--max-string-length <MAX_STRING_LENGTH>
--get <GET>
--raw
--format <FORMAT> Output format: json, yaml, toml, csv [default: json]
--input-format <INPUT_FORMAT> Input format: json, yaml, toml, csv [default: json]
--schema <SCHEMA> Path to a JSON Schema file for validation
--color <COLOR> Color output control: auto, always, never [default: auto]
--theme <THEME> Color theme (see available themes below) [default: default]
-h, --help Print help
-V, --version Print version
```
## π€ Contributing
PRs welcome! Please format with `cargo fmt` and test with `cargo test`.
## π License
Copyright Β© 2025 Lance. Licensed under MIT or Apache-2.0.