jsonist 0.0.3

A JSON formatter
Documentation
  • Coverage
  • 0%
    0 out of 28 items documented0 out of 6 items with examples
  • Size
  • Source code size: 66.27 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.36 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • peterheesterman

Jsonist

A JSON formatter

How does it work?

Jsonist tokenizes the input string you give it and then builds an Abstract Syntax Tree (AST).

It then takes the AST and produces a String of formatted JSON from the AST and the optional configuration parameter.

Example Usage

Add to your Cargo.toml:

jsonist = '0.0.3'

Then in your code you can use it like this:

extern crate jsonist;
use jsonist:: { format, FormatConfig, Delimiter, DelimiterCount, FormatterError };

fn example() {
    let json = r#"
        {
            "name": "Peter",
            "leg_count": 2,
            "languages": ["rust", "javascript", "lisp"],
            "address": {
                "street_name": "lets not put this online",
                "city": "a large one"
            },
            "winner": true
        }
    "#.to_owned();

    // let config = FormatConfig::new(Delimiter::Tabs);
    let config = FormatConfig::new(Delimiter::Spaces(DelimiterCount::Two));

    match format(json, config) {
        Ok(formatted_json) => {
            … do what you want with the 'formatted_json'
        }
        Err(e) => panic!("{}", e)
    }
}

Error types

(in case you want to handle, ignore or print them out)

  // General Tokeniser
  ExpectedMoreCharacters, InvalidTokenStartCharacter, WrongCharacter

  // Tokenising Numbers 
  InvalidNumberCharacter, ExtraDotInNumber, ExtraEInNumber, NumberLiteralEndingInE,

  // Parser
  ExpectedMoreTokens, ExpectedColonInKeyValuePair, ExpectedStringLiteral, DuplicateKeyEntry