How this tool fits your workflow
What it generates
Paste a JSON response and you get TypeScript interfaces describing its shape. The point is to skip the tedious and error-prone step of hand-typing an API contract from a sample payload, where it is easy to mistype a field name or miss that something is nullable.
The generator infers structure only from what it can see. It reads types from actual values, builds separate interfaces for nested objects, and merges array elements to work out which fields are always present.
Worked example: a user API response
Consider a response with a nested address, an array of posts where one post lacks a views field, and a bio that is null:
- Paste the JSON into the left pane. Generation runs as you type.
- The root object becomes "export interface Root", with each key typed from its value.
- The nested address object becomes its own "Address" interface, referenced as address: Address.
- The posts array becomes Post[], and because the second post has no views field, views is marked optional as "views?: number".
| JSON value | Generated type |
|---|---|
| 42 | number |
| "Ada" | string |
| true | boolean |
| ["a", "b"] | string[] |
| [1, "a"] | (number | string)[] |
| [] | unknown[] |
| { "city": "London" } | Address (a separate interface) |
| null | null — see limits |
Why merging array elements matters
Most naive generators type an array from its first element only. That produces a contract that is wrong the moment a later element differs, and the failure shows up at runtime rather than at compile time — which is the opposite of why you wanted types.
This generator collects every object in an array and takes the union of their keys. A key present in all of them is required; a key present in some is optional. That means the more representative your sample, the more accurate the output — pasting a response with twenty records gives a far better contract than one with a single record.
Common mistakes
- Trusting a one-record sample. With a single object there is no evidence any field is optional, so everything comes out required. Real APIs usually have optional fields, and you will not discover them until something is undefined at runtime.
- Treating generated types as validation. TypeScript types vanish at compile time. If the API returns something different, nothing throws — you get undefined where you expected a value. Use a runtime validator such as Zod at the boundary.
- Assuming a number is safe. JSON numbers are doubles. An ID beyond 2^53 loses precision in JavaScript regardless of what TypeScript says, which is why many APIs send large IDs as strings.
- Ignoring date strings. An ISO date arrives as a string and is typed string. If you intend to work with Date objects, that conversion is yours to write.
- Renaming the root interface but not the file. The generator always names the root Root; rename it to something meaningful before committing.
When not to use this
Related workflow
If you want a machine-checkable contract rather than compile-time-only types, the JSON Schema generator produces draft-07 schemas that a validator can enforce at runtime.
For a fine-tuning dataset or a log file, convert records with the JSONL converter first, then paste one record here to type it.
Before generating, the JSON formatter will tell you whether a response is valid and show you its structure. If the payload came from Python, the Python dict converter turns single-quoted output into real JSON.
Frequently asked questions
- How does it decide a field is optional?
- It compares every object in an array. If a key appears in some elements but not all, it is marked optional with a question mark. A single object gives no evidence of optionality, so every key is required.
- What happens to nested objects?
- Each becomes its own exported interface, named after the key holding it. Interfaces are emitted before the one that references them, so the output compiles as written.
- What about arrays of objects?
- The key name is singularised for the interface name, so a "users" array produces a User interface and the field is typed User[]. All elements are merged, so optionality is detected across the whole array.
- Why did a field come out as null?
- Because it was null in every sample. Null on its own carries no type information — the generator cannot know whether it would otherwise be a string or a number. Provide a sample where the field has a real value.
- Is my API response uploaded?
- No. Parsing and generation run in your browser, which matters because real API responses often contain customer data or tokens.