commit | d1d028278bc21ac1ce533b175ebd8830edcfa870 | [log] [tgz] |
---|---|---|
author | Callum Oakley <hello@callumoakley.net> | Tue Jun 30 16:52:13 2020 +0100 |
committer | Callum Oakley <hello@callumoakley.net> | Tue Jun 30 16:52:13 2020 +0100 |
tree | 06359426f9cc17082c874e208d59b50833f9774f | |
parent | c1c5edb54e491b29338853b3bb5169b29f3d0a5e [diff] |
0.2.8
A Rust JSON5 serializer and deserializer which speaks Serde.
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.
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, }), ); }