TypeScript types from real data
Writing the interfaces for an API response by hand is slow, and it's easy to get a field wrong. This tool reads a sample JSON and generates the TypeScript types that describe it.
Each nested object gets its own interface, named after its key (address → Address). In arrays of objects, all items are merged into a single type: if a key is missing from some of them, it's marked optional with “?”, and if a field holds values of different types, a union such as string | number is created. Identical types are declared only once.
You can choose the name of the main type, interface or type, whether to add export and whether to mark properties as readonly.
How to generate TypeScript types from JSON
- Paste a sample JSON, such as your API's response.
- Type the name of the main type (“Root” by default).
- Choose interface or type, and whether you want export and readonly.
- Click “Generate TypeScript” and copy the code or download the .ts file.
When to use it
- Typing a REST API response in a React, Angular, Vue or Node project.
- Creating the types for a JSON config file.
- Documenting the shape of the data two services exchange.
- Kick-starting the models of a new project from sample data.
Frequently Asked Questions
How does it decide which fields are optional?
In arrays of objects, a key that appears in every item is required and one that's missing from any item is optional (?). With a single sample object, every key is required; to detect optional ones, paste an array with several examples.
What type does it give null or an empty array?
A null value is typed as null (or merged with the type found in other examples, such as string | null). An empty array becomes unknown[], because there are no examples to tell what it contains.
Does it validate data at runtime?
No. TypeScript types only exist at compile time. If you need runtime validation, use a library like Zod based on these types.
Is my data sent to a server?
No. Everything is processed in your browser with JavaScript. The text you paste and the files you open never leave your device, so you can safely work with internal or customer data.
Is it free?
Yes. You can try the tool for free on one document (pasted or a single file) and change the options as often as you like; attempts that end in an error don't use up your free try. For unlimited use and processing several files at once, ToolStudio Pro costs €1.99 a month and includes every tool.