Skip to content

JSON to Rust

Generate Rust structs with serde derives from a JSON sample. Field names become snake_case with a serde rename where they differ from the JSON key, optional and nullable fields become Option types, and values of mixed type become serde_json::Value. The output derives Debug, Clone, PartialEq, Serialize and Deserialize.

Reset

Frequently asked questions

How are nested objects named?

Every nested object becomes its own Rust type, named after the key that holds it in PascalCase, so address becomes Address. Objects inside arrays take the singular of the array key, so users becomes User. Objects with exactly the same fields share one type.

When is a field optional?

When an array holds several objects and a key is missing from some of them, that field is optional: the field becomes an Option and is skipped when serializing a None. A key present in every sample is required. A single object has nothing to compare with, so all of its keys are required.

How are null values handled?

A key that is null in some samples and has a value in others becomes an Option of the type. A key that is only ever null tells the tool nothing about its real type, so it becomes Option<serde_json::Value>; paste a sample with a real value to get a precise type.

Which number types are used?

Whole numbers become i64 and numbers with a fraction become f64. A field that holds both becomes f64. Replace i64 with u32, u64 or another type if you know the range.

What happens to keys that are not valid names?

Field names are converted to snake_case and get #[serde(rename = "...")] with the original key whenever the two differ. Names that are Rust keywords, such as type, get a trailing underscore and a rename, so the struct still reads the original key.

Is my JSON uploaded or stored?

The JSON is sent to the server only to generate the code for this request and is not stored. The generator only reads the structure and the value types of your sample, so you can replace sensitive values with placeholders of the same type before you paste it.

About OneClick Pro

OneClick Pro is a free collection of more than 150 web tools for everyday work: converting images and units, formatting and validating code, checking domains and SEO, and working with text, dates and numbers. Every tool runs without registration or subscription, and what you enter is only used to calculate your result and is never stored. Use it as a quick toolbox for one-off tasks, or bookmark the tools you rely on every day.