commit | fec2e928e655e334beeeab4d1af7c1e2696a6f8d | [log] [tgz] |
---|---|---|
author | Callum Oakley <c.oakley108@gmail.com> | Mon Jan 28 21:47:28 2019 +0000 |
committer | GitHub <noreply@github.com> | Mon Jan 28 21:47:28 2019 +0000 |
tree | 6a0707afef723c7a794fa21e9301fdc063fff47e | |
parent | 34d4160a5601a420f6b4b0e645e6847deadb2c2c [diff] | |
parent | 6adaad36ebe6dcac5e64b9f190097ff348bd822b [diff] |
Merge pull request #7 from vdonich/serde_json_value Add support for int for serde_json::Value
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, }), ); }