How to use JSON to types
- 1
Paste JSON samples
Paste one response, an array of records, or several responses one after another; Sample shows two merged users.
- 2
Pick the language
Choose TypeScript, Zod, Go, Python, Java, C#, Kotlin, Swift or Rust, and the style options for it.
- 3
Name the root type
Set the name of the top-level type, for example User or OrderResponse.
- 4
Generate and copy
Press Generate types, then copy the code or download it; edits regenerate it automatically.
Limits and Pro
Free with no sign-up: 9 output languages with 3 Python styles, any number of merged samples and files up to 20 MB, with generation stopped after 30 seconds.
Pro removes the ads; the generator is the same on every plan. See Pro
About JSON to types
Writing types by hand for an API response is slow and error-prone, especially when the payload is nested three levels deep. Paste one or more JSON samples and this generator infers the structure and writes ready-to-paste definitions in nine flavours: TypeScript interfaces or type aliases, TypeScript with Zod schemas for runtime validation, Go structs with json tags, Python dataclasses, TypedDicts or Pydantic v2 models, Java records with Jackson annotations, C# classes for System.Text.Json, Kotlin data classes for kotlinx.serialization, Swift Codable structs and Rust structs for serde.
One sample rarely shows every field, so the generator merges as many as you give it. Paste several documents one after another or as JSON Lines, or an array of objects: a key that is missing from some objects becomes optional, a key that is sometimes null becomes nullable, an integer that is sometimes a decimal becomes a float, and genuinely mixed values become a union or the language's dynamic JSON type. Nested objects get their own named types — orders becomes Order, addresses becomes Address — and identical shapes are generated once and reused. Objects whose keys are numbers, UUIDs or dates are turned into maps.
Field names are converted to each language's convention, and JSON keys that differ, such as first-name or class, are mapped back with the right annotation, alias or CodingKeys. Comments and trailing commas in the sample are tolerated.
The output describes the samples you provide; the generator can't know about fields or values your samples don't contain, so review it against your API documentation before relying on it.
Privacy
Samples are parsed and the code is generated by a Web Worker in this tab, so API responses containing personal or internal data are never uploaded. The language and naming options are saved in local storage; the JSON you paste is not kept.
Features
Merges many samples
Missing keys become optional and null values nullable across all the samples you paste.
9 languages
TypeScript, Zod, Go, Python, Java, C#, Kotlin, Swift and Rust with idiomatic naming.
Key mapping included
json tags, aliases, @SerialName, @JsonProperty and CodingKeys keep the original JSON names.