#json5 #parse #parser #serde #json

json5

A Rust JSON5 serializer and deserializer which speaks Serde

13 releases

0.3.0 Nov 24, 2020
0.2.8 Jun 30, 2020
0.2.7 Apr 3, 2020
0.2.6 Mar 30, 2020
0.1.0 Jul 30, 2018

#50 in Encoding

Download history 1859/week @ 2020-12-31 2877/week @ 2021-01-07 2051/week @ 2021-01-14 2296/week @ 2021-01-21 1900/week @ 2021-01-28 2117/week @ 2021-02-04 2474/week @ 2021-02-11 2413/week @ 2021-02-18 2740/week @ 2021-02-25 3361/week @ 2021-03-04 2691/week @ 2021-03-11 3091/week @ 2021-03-18 3800/week @ 2021-03-25 3025/week @ 2021-04-01 3010/week @ 2021-04-08 2927/week @ 2021-04-15

9,368 downloads per month
Used in 19 crates (12 directly)

ISC license

40KB
975 lines

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,
        }),
    );
}

Dependencies

~1.5–2.1MB
~48K SLoC