Skip to main content

format_json

Function format_json 

Source
pub fn format_json(value: &Value, opts: &FormatOptions) -> String
Expand description

Format a JSON value as a pretty-printed string.

When opts.color is true, output includes ANSI color codes suitable for terminal display (cyan keys, green strings, yellow numbers, magenta booleans, red null).

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

let val = json!({"greeting": "hello"});
let out = format_json(&val, &FormatOptions { indent: 4, color: false });
assert!(out.contains("greeting"));