From f106c2c9d23c9c12a88b5a73f704f4be5c455926 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 27 Sep 2020 12:35:24 -0400 Subject: go-stdlib-rust post (#215) --- examples/json.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/json.rs (limited to 'examples/json.rs') diff --git a/examples/json.rs b/examples/json.rs new file mode 100644 index 0000000..bf128ed --- /dev/null +++ b/examples/json.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Author { + pub id: i32, + pub name: String, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Comment { + pub id: i32, + pub author: Author, + pub body: String, + pub in_reply_to: i32, +} + +fn main() { + let data = r#" + { + "id": 31337, + "author": { + "id": 420, + "name": "Cadey" + }, + "body": "hahaha its is an laughter image", + "in_reply_to": 31335 + } + "#; + + let c: Comment = serde_json::from_str(data).expect("json to parse"); + println!("comment: {:#?}", c); +} -- cgit v1.2.3