json-value 0.3.3

Helper method to get the json value
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use serde::ser::Serialize;
use serde_json::{ser::PrettyFormatter, Serializer, Value};

/// Serialize a [`JsonValue`] into a [`String`] with pretty formatting.
pub fn to_string_pretty(json: &Value, space: usize) -> String {
    let buf = Vec::new();
    let tab = " ".repeat(space);
    let formatter = PrettyFormatter::with_indent(tab.as_bytes());
    let mut ser = Serializer::with_formatter(buf, formatter);
    json.serialize(&mut ser).unwrap();
    String::from_utf8(ser.into_inner()).unwrap()
}