|
@ -1,4 +1,5 @@ |
|
|
use serde_json::{Value}; |
|
|
use serde_json::Value as JsonValue; |
|
|
|
|
|
use serde_yaml::Value as YamlValue; |
|
|
|
|
|
|
|
|
const JSON_STR: &str = r#"{ |
|
|
const JSON_STR: &str = r#"{ |
|
|
"demo": "key_1", |
|
|
"demo": "key_1", |
|
@ -10,12 +11,25 @@ const JSON_STR: &str = r#"{ |
|
|
] |
|
|
] |
|
|
}"#; |
|
|
}"#; |
|
|
|
|
|
|
|
|
|
|
|
const YAML_STR: &str = r#" |
|
|
|
|
|
demo: key_1 |
|
|
|
|
|
author: dnomd343 |
|
|
|
|
|
test: |
|
|
|
|
|
- 123 |
|
|
|
|
|
- 234 |
|
|
|
|
|
- 345 |
|
|
|
|
|
"#; |
|
|
|
|
|
|
|
|
fn main() { |
|
|
fn main() { |
|
|
println!("JSON raw content ->\n{}", JSON_STR); |
|
|
println!("JSON raw content ->\n{}", JSON_STR); |
|
|
|
|
|
println!("YAML raw content ->\n{}", YAML_STR); |
|
|
|
|
|
|
|
|
let data: Value = serde_json::from_str(JSON_STR).unwrap(); |
|
|
// let data: JsonValue = serde_json::from_str(JSON_STR).unwrap();
|
|
|
|
|
|
// println!("{:#?}", data);
|
|
|
|
|
|
let data: YamlValue = serde_yaml::from_str(YAML_STR).unwrap(); |
|
|
println!("{:#?}", data); |
|
|
println!("{:#?}", data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ret = serde_json::to_string(&data).unwrap(); |
|
|
let ret = serde_json::to_string(&data).unwrap(); |
|
|
println!("JSON output ->\n{}", ret); |
|
|
println!("JSON output ->\n{}", ret); |
|
|
} |
|
|
} |
|
|