About JSON Type Generator
Writing types by hand from an API response is tedious and error-prone, and the errors are the expensive kind: a field typed as required that is sometimes absent compiles perfectly and fails in production.
The difference between a usable generator and a toy is what it does with arrays. Reading only the first element of a list produces a type that describes that element and nothing else. This merges every element instead, so a field present in some objects and missing from others comes out optional, a field that is null in one place and a string in another comes out nullable, and an integer seen beside a decimal widens to a floating-point number.
JSON keys are also not identifiers. Keys like user-name, 2fa and class are all valid JSON and none of them can be a bare field name in most languages. Each language gets the treatment it actually uses — quoted keys in TypeScript, json tags in Go, @SerialName in Kotlin, CodingKeys in Swift, JsonPropertyName in C# — so the renamed field stays bound to the original key instead of silently reading nothing.
Nested objects become their own named types, named after the key that holds them, and a key holding an array is singularised so users produces a User. Types are emitted children first, which keeps the output compiling in languages that care about declaration order.
How to generate types from JSON
Paste your JSON
A full array beats a single object — the more samples, the more accurate the optional and nullable detection.
Pick your language
TypeScript, Go, Kotlin, Swift, Python or C#. Each uses that language's idioms rather than a translation of one template.
Name the root type
Nested types are named automatically from their keys.
Copy or download
The output is ready to paste into your project.
What the generator infers
- Optional — a key missing from at least one object in an array.
- Nullable — a key that is null in one sample and a real value in another.
- Integer versus floating point — whole numbers stay integers until a decimal appears alongside them.
- Nested types — each object gets its own named type, singularised when it came from an array.
- Unknown — the same key holding genuinely different types, where no single type is honest.
What it cannot know
A sample is evidence, not a specification. A field that happens to be null in every example you paste is typed as null, because nothing in the data says otherwise. A string that is always a date stays a string. An enum with three values looks exactly like a string.
Treat the output as a fast, accurate first draft rather than a finished contract. If the API has a schema — OpenAPI, JSON Schema, protobuf — that is a better source of truth, and the generated types are the thing to check it against.