JSON β TypeScript
Generate TypeScript interfaces from JSON automatically
TypeScript interfaces will appear hereβ¦
About this tool
The JSON to TypeScript converter automatically generates TypeScript interface definitions from any JSON object or array. It handles nested objects, arrays, union types from mixed arrays, and optional fields β saving the tedious manual work of writing types by hand from API responses.
When to use it
- βCreating TypeScript interfaces from API response payloads
- βGenerating types from database query results or fixture data
- βGetting a typed starting point when adding TypeScript to an existing JavaScript project
- βQuickly typing third-party API responses you don't control
Tips
- βPaste a real API response to generate accurate types β the generator infers types from actual values.
- βFor arrays with mixed element types, the generator creates union types (string | number).
- βReview generated types β null values produce type | null, which may need adjustment based on your API contract.
Frequently asked questions
Can generated interfaces replace manually written types?
They give you a solid starting point, but should be reviewed. The generator infers types from a single sample β it can't know that a field is optional (it may just be missing from that response), that an array can be empty, or that a field typed as string | null is actually always a string in production. Treat generated types as a draft.
How are null values handled in generated types?
If a field's value is null in the sample JSON, the generator produces the type null. In practice this is almost always wrong β the field is usually string | null or number | null based on non-null values in other responses. Check each nullable field and update the type to match your actual API contract.
How are deeply nested objects handled?
Nested objects generate nested interfaces. For example, { user: { name: 'Alice', role: { id: 1 } } } produces an interface Root with a user: User property, a User interface with name: string and role: Role, and a Role interface with id: number. The depth is unlimited.
How are arrays of mixed types handled?
Mixed-type arrays produce union types: an array like [1, 'hello', true] generates (number | string | boolean)[]. Homogeneous arrays produce clean types like string[]. If you see unexpected union types, check whether your sample data truly contains mixed element types or whether you need to provide a more representative sample.