Skip to content
Categories
JSON to TypeScript
Generate TypeScript type definitions from JSON.
Overview
- Automatically generates the corresponding TypeScript interface definitions from the structure of the JSON you enter.
- Nested objects are generated as separate interfaces, keeping the type definitions readable even for complex structures like API responses.
- When array elements have mixed types, they are expressed as a union type, handling the variety of shapes real JSON data can take.
Usage
- Enter the JSON you want to generate types for into the text area.
- Click the "Generate Types" button.
- Nested objects are generated as separate interfaces. Use the "Copy" button to copy the result to the clipboard.
Example
Input
{"name":"Taro","age":20,"hobbies":["reading","coding"]}Output
interface Root {
name: string;
age: number;
hobbies: string[];
}Use Cases
- Quickly creating a TypeScript type definition for the frontend from an example API response (JSON)
- Preparing a rough type skeleton before implementation, based on mock data or sample JSON
- Using a mechanically generated draft that reflects the JSON structure as a starting point before hand-writing type definitions
FAQ
Is the JSON I enter sent anywhere?
No. Type generation happens entirely in your browser, and nothing is sent to an external server.
How is the type of an array's elements determined?
If every element in the array is an object, a singular interface is generated. If the element types differ, they are expressed as a union type.
Why are some generated key names quoted?
Key names that cannot be used as TypeScript identifiers, such as those containing hyphens or starting with a digit, are automatically quoted in the output.
Notes
- The generated type definitions are inferred from the JSON values. You may need to manually adjust things like required vs. optional fields, or the distinction between null and undefined, to match the actual specification.
- Key names that cannot be used as TypeScript identifiers, such as those containing hyphens or starting with a digit, are automatically quoted in the output.
- If every element of an array is an object, they are merged into a single interface, but if the object shape differs between elements, the result may not match what you intended.
Related Tools
Validate whether JSON is correctly formatted.
Generate a TypeScript interface or Zod schema from a JSON Schema.
Convert JSON into YAML format.