L LocalUse Source

JSON to Rust

Paste a JSON response and get serde-ready Rust structs. Fields the payload can omit or send as null become Option<T> - in Rust that is not a style choice, it is the difference between deserialising and erroring out.

Root type name
Extra derives
JSON
Output

Output appears here as you type.

Runs entirely in your browser. Nothing you paste here is uploaded or stored.

Questions

Is my JSON uploaded anywhere?

No. Inference and code generation run entirely in your browser. Nothing is sent to a server, so pasting a real API response with customer data or internal URLs is safe.

Should I paste one object or an array of them?

An array, whenever you have one. Every element is merged into a single shape, so a field that is missing from some records becomes optional and a field that is sometimes null becomes nullable. One object can only ever tell the generator that everything is required.

Why does this produce different types than other converters?

Because every element of the array is merged before anything is generated. A converter that reads only the first record cannot know that a field is missing from later ones, or that it is sometimes null, so it emits a plain non-nullable type. In a statically typed language that is not a cosmetic difference: it is the line between a clean decode and a nil dereference at runtime.

Why does it matter more in Rust?

Rust has no null. A String field cannot hold one, so if the payload sends null serde fails the entire deserialisation with a type error rather than filling in a default. A converter that guesses from one record produces types that simply do not parse the second record.

What is r#type?

A raw identifier. Some JSON keys - type, match, use - are Rust keywords, and the r# prefix lets them be used as field names without renaming. A handful of keywords cannot be expressed that way, and those get a suffix plus a serde rename instead.

Do I need to run rustfmt on this?

No. The output is checked against the real rustfmt binary in this project’s tests, so it is already formatted the way your project would format it.

More code generation tools