JSON to Rust

  • serde derive
  • Option<T>
  • Instant

serde-ready structs, with rename attributes wherever the identifier differs.

Input
Rust

Paste input on the left to see rust.

Everything runs in your browser — nothing is uploaded.

About rust

Generating Rust structs from JSON produces serde-annotated types. JSONic converts fields to snake_case and adds a serde rename wherever the Rust identifier differs from the JSON key, so deserialization still matches. Keys missing from some array elements become Option<T>.

Paste JSON and get Rust structs annotated for serde. Field names are converted to snake_case, and any key whose Rust identifier differs gets an explicit serde rename so deserialization still matches. Keys absent from some array elements become Option<T>, and integral numbers map to i64 with non-integral falling back to f64.

Questions

Why is a serde rename attribute emitted?

Because Rust field names are snake_case by convention but JSON keys often are not. Without the rename, serde would look for a key that does not exist. An explicit per-field rename is more predictable than a container-level rename_all when key styles are mixed.

What about numbers that do not fit in i64?

They will not round-trip. JSON has no integer width, so a value beyond i64 needs u64 or a big-number type chosen by hand — check the range if your ids come from a system that uses unsigned 64-bit values.

Does the output compile as-is?

It needs serde with the derive feature in Cargo.toml, and serde_json if any field fell back to serde_json::Value. The struct definitions themselves are complete.