json5

Crates.iojson5
lib.rsjson5
version0.4.1
sourcesrc
created_at2018-07-30 21:46:45.448335
updated_at2021-09-21 17:53:36.305816
descriptionA Rust JSON5 serializer and deserializer which speaks Serde.
homepage
repositoryhttps://github.com/callum-oakley/json5-rs
max_upload_size
id76715
size80,134
Callum Oakley (callum-oakley)

documentation

README

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.

use json5;
use serde_derive::Deserialize;

#[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,
        }),
    );
}
Commit count: 88

cargo fmt