How to convert a Vec<serde_json::value::Value> to a JSON string?

Hello.
How to convert a Vec<serde_json::value::Value> to a JSON string without structure declaration?

Input:

let v: Vec<serde_json::value::Value> = 
vec![
     serde_json::json!({"field": 1 as u8}), 
     serde_json::json!({"field": 2 as u8})
];

Output:

[{"field": 1}, {"field": 2}]

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f14fae87b29168bbd98ad402ca3dfef6b

Have you tried :

serde_json::to_writer(std::io::stdout().lock(), &v);
// or
let s = serde_json::to_string(&v).unwrap();

playground

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.