pub fn to_string<S>(value: S) -> Result<String>
where S: Serialize,
Expand description

Serialize struct S as minified JSON with comments text. If you want to serialize as pretty formatted JSONC text, use to_string_pretty instead.

§Examples

use serde::Serialize;
#[derive(Serialize)]
struct Country {
    name: String,
    code: u32,
    regions: Vec<String>,
}
let japan = Country {
    name: "Japan".to_string(),
    code: 81,
    regions: vec!["Hokkaido".to_string(), "Kanto".to_string(), "Kyushu-Okinawa".to_string()],
};
let jp = json_with_comments::to_string(japan).unwrap();
assert_eq!(jp, r#"{"name":"Japan","code":81,"regions":["Hokkaido","Kanto","Kyushu-Okinawa"]}"#);