Last active
September 17, 2022 18:38
-
-
Save PeterWaIIace/f7ae9542a6eb163201f0100c8d0781e3 to your computer and use it in GitHub Desktop.
Python-like rust json/dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use serde_json::{Map, Value}; | |
fn main() | |
{ | |
let mut map = Map::new(); | |
let mut map2 = Map::new(); | |
// assuming keys_vals is a Vec<(String, String)> | |
map.insert("key1".to_string(), Value::String("val".to_string())); | |
map.insert("key2".to_string(), Value::String("val2".to_string())); | |
map.insert("key3".to_string(), Value::String("val3".to_string())); | |
map.insert("key4".to_string(), Value::Object(map2)); | |
let obj = Value::Object(map); | |
println!("{}",obj) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment