How to generate types from JSON
- Paste a sample JSON response or document. The more complete the sample, the better the types.
- Pick a target: TypeScript interfaces, a Zod schema, Go structs, Python dataclasses or Pydantic models, Rust serde structs, C# classes, Java records or a JSON Schema.
- Set the root type name, for example
UserorApiResponse. Nested objects get their own named types based on their keys. - Copy the code or download it as a source file.
How types are inferred
The generator walks your JSON and records every type it sees for each key. Arrays of objects are merged, so if one order has a coupon field and another does not, coupon becomes optional. Values that are sometimes null become nullable (string | null, Optional[str], *string or Option<String>). Mixed types become a union where the language supports it.
Integers and decimals are told apart where it matters: Go gets int64 or float64 and Rust i64 or f64. Keys that are not valid identifiers, such as first-name, are converted to the language's naming style and keep the original key via a JSON tag, alias or rename attribute, so serialisation still matches.
Inference only sees the sample, so check the result: an empty array becomes unknown[] and an ID that happens to be numeric in your sample will be typed as a number.
Privacy
Everything runs in your browser. Your JSON, which may contain production data, never leaves your device.
Should I use interface or type in TypeScript?
For object shapes both work. Interfaces are generated here because they give clearer error messages and can be extended. Use the Zod option if you also need runtime validation.
Why are some Go fields pointers?
Fields that are optional or can be null become pointers so your code can tell a missing value from a zero value such as 0 or an empty string.
Can I generate types from a JSON array?
Yes. Paste the array and all items are merged into one element type, then the root becomes an array of it.