JSON to Rust
JSON to Rust. Infers types from an example JSON document. Nested objects become named types by their key; mixed-type arrays fall back to a broad/any type. Runs on your device.
Runs on your device. The file is never uploaded.
JSON to Rust writes a struct for each object in the example, every one carrying #[derive(Debug, Serialize, Deserialize)]. A key that is not lowercase snake_case is renamed with a serde attribute back to its original spelling. Nothing else is emitted: no use statements, so serde and serde_json belong in your Cargo.toml already.
Questions
What does the generated code look like?
One struct per object in your example, each with #[derive(Debug, Serialize, Deserialize)] above it. The top-level struct is called Root, nested ones are named after the key that holds them, and they are printed innermost first so the file compiles top to bottom with no forward references.
Which Rust types does it use?
String for strings, bool for booleans, i64 for whole numbers and f64 for fractional ones. An array becomes Vec<T> with T taken from its first element, and a nested object becomes a struct named after its key. A null becomes Option<serde_json::Value>, and an empty array's element type becomes serde_json::Value.
Do I need serde in my project?
Yes. The derive names Serialize and Deserialize, and some fields can mention serde_json::Value, so add serde with the derive feature and serde_json to your Cargo.toml. The tool emits no use statements or attributes beyond the derive, so bring those into scope yourself.
What happens to keys that are not snake_case?
They get a rename attribute. A key that does not match lowercase letters, digits and underscores gets #[serde(rename = "...")] with the original key, and the field itself is lowercased with the other characters replaced by underscores. So userName becomes a username field with a rename back to userName.
Are fields optional?
No. Every field is required, because the generator sees a single example and cannot tell which keys might be missing from another response. Wrap the ones that can be absent in Option yourself, or add serde defaults. The same applies to a field that holds more than one type, which needs an enum you write by hand.
Does my JSON get uploaded?
No. Parsing and code generation run in a Web Worker in this tab. That matters when the example you drop in is a real API response with live values in it, since none of it leaves your machine. Nothing is uploaded, nothing is logged, and the page works offline after the first load.