json-colorizer
A fast, lightweight JSON formatter, pretty-printer, colorizer, and query tool for Rust — with jq-style dot-path queries.
Features
- 🎨 Syntax-colored JSON output (cyan keys, green strings, yellow numbers, magenta bools, red null)
- 📐 Pretty-print with configurable indentation
- 📦 Compact mode (minified single-line output)
- 🔍 jq-style queries —
.data.users[0].name - 📄 Read from stdin or file
- 🔌 Use as a library or a CLI tool
Install (CLI)
CLI Usage
# Pretty-print with colors
|
# Compact output
|
# Query nested values
|
# Read from file
Library Usage
Add to your Cargo.toml (no CLI dependencies pulled in):
[]
= { = "0.1", = false }
use ;
use json;
let data = json!;
// Pretty-print (with ANSI colors)
println!;
// Pretty-print (no colors, custom indent)
let opts = FormatOptions ;
println!;
// Compact
println!;
// Query
let name = query.unwrap;
assert_eq!;
API
| Function | Description |
|---|---|
format_json(value, opts) |
Pretty-print with optional ANSI colors |
format_json_compact(value) |
Minified single-line output |
query(value, path) |
Dot-path query → Result<&Value, QueryError> |
parse_and_format(str, opts) |
Parse JSON string → formatted output |
Types
FormatOptions—indent: usize(default 2),color: bool(default true)QueryError—KeyNotFound,IndexOutOfBounds,InvalidQuery
License
MIT