Rust Struct Generator
Rust Struct Generator gives you a starting point from one sample; the API's own schema is what tells you which fields are genuinely optional.
🔒 This tool runs entirely in your browser. Your files are never uploaded to a server.
Developer
Rust Struct Generator
Frontend preview — no upload or external service.
Rust structs
Three nested structs with #[derive(Serialize, Deserialize, Debug)], user_id renamed from userId, and email typed as Option<String> because the sample was null.
How the Rust Struct Generator works
- Paste a representative JSON sample — one that includes every optional field populated, not just the minimal case.
- Choose the derives and whether to rename fields to snake_case with serde rename attributes.
- Copy the structs into your crate and check the Option types against what the API actually guarantees.
FAQ
Why are some fields Option?
Because the sample had null there, or the field was absent. A field that is always present in your sample will be generated as a plain type, which will panic on deserialisation the first time the API omits it.
Does one JSON sample give correct types?
It gives types consistent with that sample. Integers that happen to be small become i64, and a field that is a string in one response and a number in another will not be caught. Check against the API's schema.
What about snake_case renaming?
Rust convention is snake_case fields, while most JSON APIs use camelCase. Generating serde rename attributes keeps both sides idiomatic without a manual mapping layer.
How we compare
| Feature | Online Tool Store | A CLI script | An IDE plugin |
|---|---|---|---|
| serde derives included | ✓ | ✗ | ✓ |
| Option for nullable | ✓ | ✗ | ✓ |
| Nothing uploaded | ✓ | Local | ✗ |
| No install | ✓ | ✗ | ✓ |
Rust Struct Generator gives you a starting point from one sample; the API's own schema is what tells you which fields are genuinely optional.