- JSON
- json
- serde_json
- chrono
JSON serialize examples
examples/json/json-serialize/Cargo.toml
[package] name = "json-serialize" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] serde_json = "1.0" chrono = "0.4.26"
examples/json/json-serialize/src/main.rs
use chrono::{DateTime, Utc}; use serde_json::json; fn main() { let name = "Foo Bar"; let number = 42; let numbers = vec![19, 23]; let utc: DateTime<Utc> = Utc::now(); //println!("{}", utc); let json_str = &json!({ "name": name, "number": number, "vector of numbers": numbers, "now": utc.timestamp(), }); println!("{}", json_str); }
{"name":"Foo Bar","now":1720675653,"number":42,"vector of numbers":[19,23]}