commit | 94cc383f2ccf175a8c3371afaaafa07ccbd4c27d | [log] [tgz] |
---|---|---|
author | Callum Oakley <c.oakley108@gmail.com> | Sun Nov 04 17:08:14 2018 +0000 |
committer | Callum Oakley <c.oakley108@gmail.com> | Sun Nov 04 17:08:14 2018 +0000 |
tree | c5049df6cd85f9a95d710f2aa0edbf931a5a3522 | |
parent | 18f93c3d685cc13a246d22d2a60ee0818cf2b9c2 [diff] |
readme badges
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 in to a struct.
extern crate json5; #[macro_use] extern crate serde_derive; #[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, }), ); }