extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; #[derive(Serialize)] struct Foo { bar: i32 } fn main() { let s = serde_json::to_string(&Foo { bar: 42 }) .expect("Unable to serialize foo"); println!("{}", s); }