JSON to TypeScript Types
Paste a JSON response and get TypeScript interfaces or type aliases, with nested objects, optional keys and nullable fields inferred.
Free · No sign-up · Your inputs stay in your browser
Input
Generate TypeScript types from JSON
Output
TypeScript
312 characters
Types are inferred from this one sample. A key missing from some items of an array becomes optional (?), and a null becomes | null. A field that is always null in the sample cannot be typed beyond null: give the sample a real value.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
One sample is a guess
A type generated from one response describes that response. Fields that were null in the sample, optional fields that happened to be present, and enums that happened to hold one value are all guessed wrong. Use the output as a first draft and correct it against the API's documentation or schema.
Types are not validation
TypeScript types disappear at runtime, so const user: User = await res.json() asserts a shape it never checks. For data crossing a trust boundary, validate it with a schema library and derive the type from the schema; the JSON to Zod tool on this site generates one from the same sample.
Interface or type?
For object shapes they are interchangeable in almost every case. The TypeScript handbook notes that interfaces can be extended by declaration merging and types cannot; pick one for a codebase and stay with it.