A Rust JSON5 serializer and deserializer which speaks Serde.
Switch branches/tags
Nothing to show
Clone or download
Latest commit e855e7d Nov 30, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src first pass documentation Nov 30, 2018
tests use pest 2.0 unicode builtins Oct 2, 2018
.gitignore playing with pest (simple incomplete json parser) Jun 23, 2018
Cargo.toml 0.2.2 Nov 30, 2018
LICENCE cargo metadata and lisence Jul 30, 2018
README.md first pass documentation Nov 30, 2018

README.md

JSON5

crates.io docs.rs

A Rust JSON5 serializer and deserializer which speaks Serde.

API

Deserialize a JSON5 string with from_str. Go the other way with to_string. The serializer is very basic at the moment, it just produces plain old JSON. See the Serde documentation for details on implementing Serialize and Deserialize. (Usually it's just a case of sprinkling in some derives.)

The Serde data model is mostly supported, with the exception of bytes and borrowed strings.

Example

Read some config into a struct.

extern crate json5;
#[macro_use]
extern crate serde_derive;

#[derive(Deserialize, Debug, PartialEq)]
struct Config {
    message: String,
    n: i32,
}

fn main() {
    let config = "
        {
          // A traditional message.
          message: 'hello world',

          // A number for some reason.
          n: 42,
        }
    ";

    assert_eq!(
        json5::from_str(config),
        Ok(Config {
            message: "hello world".to_string(),
            n: 42,
        }),
    );
}