Skip to main content

Crate json_colorizer

Crate json_colorizer 

Source
Expand description

§json-colorizer

A fast, lightweight JSON formatter, pretty-printer, colorizer, and query library for Rust.

Use it to pretty-print JSON with syntax highlighting in the terminal, compact-print JSON, or query nested values with dot-path notation.

§Quick Start

use json_colorizer::{format_json, format_json_compact, query, FormatOptions};
use serde_json::json;

let value = json!({"name": "Alice", "scores": [95, 87, 100]});

// Pretty-print with colors
let output = format_json(&value, &FormatOptions::default());
println!("{}", output);

// Compact output
let compact = format_json_compact(&value);
println!("{}", compact);

// Query a nested value
let score = query(&value, ".scores[0]").unwrap();
assert_eq!(score, &json!(95));

Structs§

FormatOptions
Options for controlling JSON output formatting.

Enums§

QueryError
Error returned when a query path is invalid or does not match the JSON.

Functions§

format_json
Format a JSON value as a pretty-printed string.
format_json_compact
Format a JSON value as a compact (single-line, no whitespace) string.
parse_and_format
Parse a raw JSON string and return the formatted (colorized) output.
query
Query a nested value inside root using a dot-path string.