JSON to TypeScript Generator
Generate a TypeScript type from a sample JSON file or API response. Choose a name for the exported type and get a starting point for fields, nested objects and arrays.
If the sample fails to parse, find the syntax error in the JSON before generating the type.
- Use it when
- You’re writing TypeScript that reads an API response. Generate a starting type from a sample response.
- Keep in mind
- The generated type only reflects the sample. Check fields that can be missing or have other types.
{"id":7}export type Row = {
id: number;
};This output is inferred from your sample. Review it before use.
Your input stays in this browser. We don’t upload it. How we handle your data .
How to generate TypeScript types
Paste sample JSON or open a file, choose a root type name and select Generate TypeScript.
Frequently asked questions
How do I use a generated TypeScript type?
Choose a root type name and generate the output. Add the exported type to a .ts file, then import it as a type where you work with that response or file.
When does the generator mark a field as optional?
A field becomes optional if it appears in some of the objects in an example array and is missing from others. Include representative records so the generated type reflects the fields your API may omit.
What happens when a field has different types in different records?
The generator combines the observed types in a union. For example, if one record has a numeric ID and another has a text ID, the generated type allows both number and string.
Can the generated type check incoming JSON at runtime?
TypeScript types help check your code during development. To check data when it arrives, use a runtime validator. You can generate a draft JSON Schema from a sample and review it before using it with a schema validator.