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.

My Github Page: https://github.com/liweinan

Powered by Jekyll and Theme by solid

If you have any question want to ask or find bugs regarding with my blog posts, please report it here:
https://github.com/liweinan/liweinan.github.io/issues