How to generate TypeScript from JSON
- Paste a sample response into Input, drop a
.jsonfile on the page, or press Open file. - The types appear as you type. Change Root name, choose interface or type alias, and turn on Add export if you want to import them.
- Select Copy or Download to save
types.ts.
If the sample is not valid JSON, you see the line and column of the problem instead of types.
How types are inferred
The tool reads your sample and describes what it sees:
- Strings, numbers, booleans and null become the matching TypeScript types.
- Each nested object becomes its own named interface, so the output stays readable.
- Arrays of objects are merged into one interface. A key found in only some items becomes optional.
- Mixed values become a union, and an empty array becomes
unknown[]. - Keys that are not valid identifiers, such as
my-key, are written in quotes.
Get better results
A sample shows only what it contains. If one field is sometimes a number and sometimes missing, include examples of both, or paste an array with several records so the tool can merge them. Treat the output as a starting point and check it against your API documentation: a sample cannot tell the difference between a Date and a string, or between an enum and a plain string.
Tips
- Format the sample first with the JSON formatter to make sure it is valid.
- Explore a large response with the JSON tree viewer and paste only the part you need.
- Need config instead of types? Try JSON to YAML.
- Use type alias if you plan to combine the result with unions elsewhere.
Privacy
Real responses can contain private data. The generator runs in your browser and your sample never leaves your device.