pub fn stringify_jsonc(
formatted: &Formatted<Value>,
options: Option<FormatOptions>,
) -> Result<String>Expand description
Stringifies a JSONC value (as plain JSON) with preserved formatting.
Examples found in repository?
examples/parse_jsonc.rs (line 21)
5fn main() {
6 let text = r#"
7{
8 // config for the app
9 "name": "my-app",
10 "port": 3000,
11 "debug": true
12}
13"#;
14
15 let formatted = parse_jsonc(text, None, None).expect("parse");
16 println!(
17 "Parsed: {} port={}",
18 formatted.value["name"], formatted.value["port"]
19 );
20
21 let out = stringify_jsonc(&formatted, None).expect("stringify");
22 println!("Stringify (comments stripped, valid JSON):\n{}", out);
23
24 let opts = JsoncExtraOptions {
25 allow_trailing_comma: true,
26 ..Default::default()
27 };
28 let with_trailing = r#"{ "x": 1, }"#;
29 let parsed = parse_jsonc(with_trailing, None, Some(opts)).expect("parse with trailing comma");
30 println!("With trailing comma: {:?}", parsed.value);
31}