Char format about println!

let data: Value = serde_json::from_str(json_data).unwrap();
println!("json.msg: {}", data["msg"]);

how can i put
data["msg"]
into {}

just like

let system = std::env::consts::OS;
println!("Running on {system} OS");

later looks more elegant

That's debatable and at best subjective. Rust doesn't currently allow (and doesn't plan to allow) arbitrary expressions in format strings. If you want to use the newer interpolation syntax, you'll have to pull the value out into a variable.

1 Like
let data: Value = serde_json::from_str(json_data).unwrap();
println!("json.msg: {msg}", msg=data["msg"]);
4 Likes

i get it

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.