expression
JSON integer precision and interoperability
A JSON number can exceed the exact integer range of some consumers. Rust can store large u64 values, but cross-language schemas may prefer decimal strings for identifiers to avoid rounding. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): true "9007199254740993" Common mistake: Assuming every JSON consumer preserves all u64 integers exactly.
Formal Syntax & Structure
rust syntaxrust
serde_json::Value::as_u64(); decimal strings for large IDsWorking Example
Example Snippetrust
fn main() { let n: u64 = 9_007_199_254_740_993; let value = serde_json::json!(n); println!("{}", value.as_u64() == Some(n)); let wire = serde_json::to_string(&n.to_string()).unwrap(); println!("{wire}");}