Crate formatjson

Source
Expand description

Validate and format JSON files.

The formatjson command is available as a binary, which reads and formats JSON files in-place, and library functions are available to use or extend the functionality.

§Examples

  • As a command-line tool:

    $ formatjson example.json
    Successfully formatted example.json
  • As a library:

    fn main() {
        let json = formatjson::format_json(r#"{"foo":"bar"}"#).unwrap();
        println!("{}", json);
    }
    $ cargo run
    {
      "foo": "bar"
    }

Re-exports§

pub use errors::FormatJsonError;

Modules§

errors
Errors raised by the library.
token_formatter
Contains the token formatter struct, which consumes and formats tokens.
tokenizer
Tokenizes a given JSON string, without validating its syntax.
validator
Validates the tokens generated by the tokenizer.

Functions§

format_json
Returns a new, formatted JSON string.
format_json_file
Reads, formats, and overwrites the given JSON file.