JSON to TypeScript Generator
Developer Tools · Added 18 August 2026
Paste an API response and get the TypeScript that describes it. Objects that appear in several places are emitted once and reused, fields missing from some array items become optional, and the result panel says plainly what a single sample cannot tell you — which is the part most generators leave you to discover in production.
How to use the json to typescript generator
- 1Paste a JSON sample — a real API response works better than a hand-written one.
- 2Name the root type after what it represents, such as UserResponse.
- 3Choose interface or type alias, and whether declarations should be exported.
- 4Turn on string literal unions if repeated string values represent a fixed set, such as a status field.
- 5Press Generate, then read the notes about what the sample could not determine.
Examples
A nested response
- Input
- { "id": 1, "owner": { "name": "Ada", "email": "ada@example.com" } }
- Result
- interface Root with id: number and owner: Owner, plus a separate Owner interface
An array whose items disagree
- Input
- [{ "env": "prod", "healthy": true }, { "env": "staging", "healthy": false, "note": "flaky" }]
- Result
- note?: string — optional, because it is absent from one of the items
Literal unions
- Input
- Three objects whose status field is "active", "paused" and "active"
- Result
- status: "active" | "paused" when literal inference is on, instead of string
About the json to typescript generator
Types from a sample, and the limits of that
Generating types from JSON is inference from one observation. It is genuinely useful — it saves a tedious half hour and it catches structure you would have missed reading the response by eye — but everything it produces is a hypothesis about the API, not a description of it.
The failure mode worth naming: a generated type that marks every field required gives you a compiler that confidently enforces a contract the server never agreed to. The code type-checks, ships, and throws at runtime the first time a field is omitted. Generating optional fields where the sample disagrees, and flagging what the sample cannot answer, is the difference between a useful draft and a false sense of safety.
How shapes are merged
Every element of an array is described separately and then unified. Objects with matching shapes fuse into one type; objects that differ produce a merged type with the differing fields marked optional; genuinely different kinds of value produce a union.
Identical shapes appearing at different points in the document are emitted once and referenced by name, which is what a person writing the types by hand would do. The naming follows the key that introduced the shape, singularised when the key is plural — a deployments array yields a Deployment interface.
Where to go from the draft
Two habits make generated types pull their weight. First, keep them in the repository rather than regenerating on demand: when the API changes, the diff tells you what changed, which is information you cannot get any other way without reading a changelog.
Second, validate at the boundary. TypeScript types are erased at compile time and enforce nothing at runtime, so a response that does not match produces no error at the point where it entered your program — it produces one much later, somewhere confusing. A runtime schema check where the data arrives turns that into an error message that names the field.
Frequently asked questions
Why is a field optional when it is present in my sample?
Why does a null field become unknown | null?
What about an empty array?
It warned about a large number. Why?
Should I use these types as-is?
Does anything get sent to a server?
Related tools
JSON Formatter
Developer Tools
Pretty-print, minify and inspect JSON with precise error positions.
JSON Validator
Developer Tools
Check JSON validity and get a structural summary — depth, key count and type breakdown.
JSON to YAML Converter
Developer Tools
Convert JSON to YAML or YAML back to JSON, with the ambiguous values quoted.