Struct jsonxf::Formatter [] [src]

pub struct Formatter {
    pub indent: String,
    pub line_separator: String,
    pub record_separator: String,
    pub after_colon: String,
    pub trailing_output: String,
    // some fields omitted
}

Formatter allows customizable pretty-printing, minimizing, and other formatting tasks on JSON-encoded UTF-8 data in string or stream format.

Example:

let mut fmt = jsonxf::Formatter::pretty_printer();
fmt.line_separator = String::from("\r\n");
assert_eq!(
    fmt.format("{\"a\":1}").unwrap(),
    "{\r\n  \"a\": 1\r\n}"
);

Fields

Used for beginning-of-line indentation in arrays and objects.

Used inside arrays and objects.

Used between root-level arrays and objects.

Used after a colon inside objects.

Used at very end of output.

Methods

impl Formatter
[src]

[src]

Returns a Formatter set up for pretty-printing. Defaults to using two spaces of indentation, Unix newlines, and no whitespace at EOF.

Example:

assert_eq!(
    jsonxf::Formatter::pretty_printer().format("{\"a\":1}").unwrap(),
    "{\n  \"a\": 1\n}"
);

[src]

Returns a Formatter set up for minimizing. Defaults to using Unix newlines between records, and no whitespace at EOF.

Example:

assert_eq!(
    jsonxf::Formatter::minimizer().format("{  \"a\" : 1  }\n").unwrap(),
    "{\"a\":1}"
);

[src]

Formats a string of JSON-encoded data.

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

Example:

let mut fmt = jsonxf::Formatter::pretty_printer();
fmt.indent = String::from("\t");
fmt.trailing_output = String::from("\n");
assert_eq!(
    fmt.format("{\"a\":1}").unwrap(),
    "{\n\t\"a\": 1\n}\n"
);

[src]

Formats a stream of JSON-encoded data.

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

Example:

let mut fmt = jsonxf::Formatter::pretty_printer();
fmt.indent = String::from("\t");
fmt.trailing_output = String::from("\n");
match fmt.format_stream(&mut std::io::stdin(), &mut std::io::stdout()) {
    Ok(_) => { /* YAY */ },
    Err(e) => { panic!(e.to_string()); }
}