15 releases

0.4.1 Sep 21, 2021
0.3.0 Nov 24, 2020
0.2.8 Jun 30, 2020
0.2.6 Mar 30, 2020
0.1.0 Jul 30, 2018

#37 in Encoding

Download history 120517/week @ 2024-01-05 135583/week @ 2024-01-12 146087/week @ 2024-01-19 143496/week @ 2024-01-26 166415/week @ 2024-02-02 162218/week @ 2024-02-09 159778/week @ 2024-02-16 168125/week @ 2024-02-23 174408/week @ 2024-03-01 180401/week @ 2024-03-08 182013/week @ 2024-03-15 179907/week @ 2024-03-22 174351/week @ 2024-03-29 184358/week @ 2024-04-05 190514/week @ 2024-04-12 157740/week @ 2024-04-19

741,743 downloads per month
Used in 242 crates (107 directly)

ISC license

40KB
956 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

~2.3–3MB
~64K SLoC