diff --git a/to-json/Cargo.lock b/to-json/Cargo.lock index 3efbc0d..e209a54 100644 --- a/to-json/Cargo.lock +++ b/to-json/Cargo.lock @@ -2,6 +2,39 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "serde" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" + +[[package]] +name = "serde_json" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "to-json" version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] diff --git a/to-json/Cargo.toml b/to-json/Cargo.toml index 4047338..8653059 100644 --- a/to-json/Cargo.toml +++ b/to-json/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = "1.0.145" +serde_json = "1.0.86" diff --git a/to-json/src/main.rs b/to-json/src/main.rs index e7a11a9..a8f5bef 100644 --- a/to-json/src/main.rs +++ b/to-json/src/main.rs @@ -1,3 +1,22 @@ +use serde_json::{Value}; + +fn json_str() -> String { + let json = r#"{ + "demo": "key_1", + "author": "dnomd343", + "test": [ + "123", + "234", + "345" + ] +}"#; + return String::from(json); +} + fn main() { - println!("Hello, world!"); + let raw = json_str(); + println!("JSON raw content ->\n{}", raw); + + let parsed: Value = serde_json::from_str(&raw[..]).unwrap(); + println!("Author -> {}", parsed["author"]); }