macro

json! macro: build structured JSON

Construct a Value from literals and serializable Rust expressions. Use normal serialization rather than assembling quoted strings manually. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): گزارش true Common mistake: Assuming json! accepts arbitrary non-serializable Rust types.

Formal Syntax & Structure

rust syntaxrust
serde_json::json!({...})

Working Example

Example Snippetrust
fn main() {    let name = "گزارش";    let v = serde_json::json!({"name": name, "done": true});    println!("{} {}", v["name"].as_str().unwrap(), v["done"].as_bool().unwrap());}
Rust Reference