Skip to content

Instantly share code, notes, and snippets.

@PeterWaIIace
Last active September 17, 2022 18:38
Show Gist options
  • Save PeterWaIIace/f7ae9542a6eb163201f0100c8d0781e3 to your computer and use it in GitHub Desktop.
Save PeterWaIIace/f7ae9542a6eb163201f0100c8d0781e3 to your computer and use it in GitHub Desktop.
Python-like rust json/dictionary
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