Rust Tuple to Json
Here is the code to convert a rust tuple to JSON string:
let my_list: Vec<(i32, String)> = vec![
(1, "abc".to_string()),
(2, "feg".to_string()),
(3, "xyz".to_string()),
];
let serialized = serde_json::to_string(&my_list).unwrap();
println!("serialized = {}", serialized);
Here is the output of the code:
serialized = [[1,"abc"],[2,"feg"],[3,"xyz"]]
As the output shown above, we can see the tuple type is serialized as JSON arrays.