#serde-json #json5 #json #parser

json5

A Rust JSON5 serializer and deserializer which speaks Serde

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

#34 in Parser implementations

Download history 392637/week @ 2025-01-28 389084/week @ 2025-02-04 386689/week @ 2025-02-11 333060/week @ 2025-02-18 312184/week @ 2025-02-25 698336/week @ 2025-03-04 605920/week @ 2025-03-11 1020452/week @ 2025-03-18 820092/week @ 2025-03-25 497870/week @ 2025-04-01 486241/week @ 2025-04-08 319972/week @ 2025-04-15 317853/week @ 2025-04-22 315047/week @ 2025-04-29 353793/week @ 2025-05-06 278785/week @ 2025-05-13

1,307,686 downloads per month
Used in 437 crates (157 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.1–3MB
~60K SLoC