json_value/methods/
mod.rs

1use serde::ser::Serialize;
2use serde_json::{ser::PrettyFormatter, Serializer, Value};
3
4/// Serialize a [`JsonValue`] into a [`String`] with pretty formatting.
5pub fn to_string_pretty(json: &Value, space: usize) -> String {
6    let buf = Vec::new();
7    let tab = " ".repeat(space);
8    let formatter = PrettyFormatter::with_indent(tab.as_bytes());
9    let mut ser = Serializer::with_formatter(buf, formatter);
10    json.serialize(&mut ser).unwrap();
11    String::from_utf8(ser.into_inner()).unwrap()
12}