JSON to Rust Converter

Generate Rust structs, Serde field mappings and Option types from JSON objects or multiple samples. Download a ready-to-integrate Rust source file.

How to generate Rust models

Paste a representative JSON object or array, choose a root type name and run the generator. Use the file selector to inspect each source file; Copy copies only the selected file. Download ZIP keeps all generated files together. Original JSON field names are mapped in complete output even when they are language keywords or contain punctuation.

Output derives Serialize and Deserialize. Add serde with its derive feature and serde_json to Cargo.toml, then include the generated source as a module. This is a model file, not a complete Cargo application. Option fields represent null or optional values; JSON integer samples must fit signed 64-bit range.

Samples, optional fields and limits

For several responses of the same shape, select JSON Lines and put one JSON document on each line. Fields missing from some object samples become optional; an explicit null contributes a nullable type. Empty arrays and null-only fields do not contain enough evidence to infer a precise element or value type. Add representative samples and review the generated model.

String values stay strings, including numeric IDs, dates and UUIDs. This infers a model from examples, not a full API contract. Limits: 200,000 characters, 64 nesting levels, 50 sample documents, 50 generated files and 1,000,000 output characters. Processing runs locally in a cancellable worker with a 10-second deadline.

Questions & answers

Are missing fields the same as null?

No. Missing fields indicate optional membership; null is a value. The target language may represent both through an optional or nullable type. Provide multiple samples and use All fields optional only when that matches your application.

Does this fetch schemas or send JSON to an API?

No. Only the JSON samples you enter are used. No schema URLs or JSON strings are fetched, and the generated program is not executed on this page.

Other Languages