json-colorizer
A high-performance JSON formatter, pretty-printer, colorizer, and query tool for Rust — with advanced jq-style queries and NDJSON support.
Features
- 🎨 Powerful Colorization — Vibrant syntax highlighting using a high-performance formatter.
- 🔍 Advanced Queries — Support for wildcards (
.*,[]), array slicing ([0:5]), and multiple results. - 🥞 NDJSON Support — Process streams of multiple JSON objects (Newline Delimited JSON).
- 📐 Pretty-print — Configurable indentation and key sorting.
- 📦 Compact mode — Minified single-line output.
- 🔌 Library & CLI — Clean API for Rust projects or a standalone CLI tool.
- ⚡ High Performance — Leverages
serde_json::ser::Formatterfor efficient streaming output.
Install (CLI)
CLI Usage
# Pretty-print with colors
|
# Sort object keys alphabetically
|
# Advanced Querying (Wildcards & Slices)
# Get all names from an array of objects
|
# Array slicing
|
# Raw output (omit quotes for strings, ideal for piping)
# Process NDJSON (multiple objects)
|
CLI Flags
| Flag | Short | Description |
|---|---|---|
--compact |
-c |
Minified single-line output |
--query |
-q |
Dot-path query (e.g. .users[0].name) |
--raw-output |
-r |
Raw output (no quotes for strings) |
--sort-keys |
-S |
Sort object keys alphabetically |
--indent |
-i |
Custom indentation size (default: 2) |
Library Usage
Add to your Cargo.toml:
[]
= "0.1"
use ;
use json;
let data = json!;
// Pretty-print (with default theme)
println!;
// Query (returns a Vec of matches)
let results = query.unwrap;
assert_eq!;
// Custom Formatting
let opts = FormatOptions ;
println!;
API
| Function | Description |
|---|---|
format_json(value, opts) |
Pretty-print with theme-based colorization |
format_json_compact(value) |
Minified single-line output |
query(value, path) |
Advanced query → Result<Vec<&Value>, QueryError> |
parse_and_format(str, opts) |
Parse JSON string → formatted output |
Types
FormatOptions—indent,color,sort_keys,themeTheme— Customizable colors forkey,string,number,boolean,nullQueryError—KeyNotFound,IndexOutOfBounds,InvalidQuery
License
MIT