diff --git a/to-json/src/main.rs b/to-json/src/main.rs index a8f5bef..20144fe 100644 --- a/to-json/src/main.rs +++ b/to-json/src/main.rs @@ -1,7 +1,6 @@ use serde_json::{Value}; -fn json_str() -> String { - let json = r#"{ +const JSON_STR: &str = r#"{ "demo": "key_1", "author": "dnomd343", "test": [ @@ -10,13 +9,13 @@ fn json_str() -> String { "345" ] }"#; - return String::from(json); -} fn main() { - let raw = json_str(); - println!("JSON raw content ->\n{}", raw); + println!("JSON raw content ->\n{}", JSON_STR); + + let data: Value = serde_json::from_str(JSON_STR).unwrap(); + println!("{:#?}", data); - let parsed: Value = serde_json::from_str(&raw[..]).unwrap(); - println!("Author -> {}", parsed["author"]); + let ret = serde_json::to_string(&data).unwrap(); + println!("JSON output ->\n{}", ret); }