[][src]Function jsonxf::pretty_print

pub fn pretty_print(json_string: &str) -> Result<String, String>

Pretty-prints a string of JSON-encoded data.

Input must be valid JSON data in UTF-8 encoding.

The output will use two spaces as an indent, a line feed as newline character, and no trailing whitespace. To customize this behavior, use a jsonxf::Formatter::pretty_printer() directly.

Examples:

assert_eq!(
    jsonxf::pretty_print("{\"a\":1,\"b\":2}").unwrap(),
    "{\n  \"a\": 1,\n  \"b\": 2\n}"
);
assert_eq!(
    jsonxf::pretty_print("{\"empty\":{},\n\n\n\n\n\"one\":[1]}").unwrap(),
    "{\n  \"empty\": {},\n  \"one\": [\n    1\n  ]\n}"
);