JSON to TypeScript Interface Generator
Paste JSON and get ready-to-use TypeScript interfaces, with nested types, arrays and optional fields.
JSON Input
TypeScript
What Is a JSON to TypeScript Converter?
A JSON to TypeScript converter reads example JSON, like an API response, and writes TypeScript interfaces that describe its shape. Instead of typing every field by hand, you get correct types in one click and can paste them straight into your project.
How to Generate TypeScript Interfaces
- Paste a sample of your JSON, or drop a .json file on the box.
- Choose a name for the main interface (Root by default).
- Click Generate TypeScript, or press Ctrl + Enter.
- Click Copy, or Download the types.ts file.
Features
- Detects string, number, boolean, null, arrays and nested objects.
- Creates a named interface for each nested object, like Address or Order.
- Merges array items and marks fields that are not always present as optional.
- Union types such as string | null when values differ.
- Runs in your browser. Your JSON is never uploaded.
Example
{
"id": 1024,
"name": "Emily Clark",
"manager": null,
"address": { "city": "London", "zip": "SW1A 1AA" },
"orders": [
{ "id": 1, "total": 49.5 },
{ "id": 2, "total": 12, "coupon": "SAVE10" }
]
}export interface Root {
id: number
name: string
manager: null
address: Address
orders: Order[]
}
export interface Address {
city: string
zip: string
}
export interface Order {
id: number
total: number
coupon?: string
}The nested object becomes its own Address interface, the array becomes Order[], and coupon is marked optional with ? because only one order has it.
Tips for Better Types
- Use a complete sample. The tool can only see the fields in your example. Include an item with every optional field if you can.
- Check null values. A field that is
nullin your sample becomesnull. If it can also be a string, change it tostring | null. - Types are not checked at runtime. TypeScript types disappear after compiling. To validate real API data, use a JSON Schema with the JSON Schema Generator and JSON Schema Validator, or create a Zod schema with JSON to Zod.
- Typing JSON.parse and fetch results: see JSON in TypeScript for why
as Useris unsafe and what to use instead. - Need sample data for your types? Create realistic mock records with the JSON Generator.
Interface or Type?
Both describe the shape of an object, and for API data they work the same. Interfaces can be extended and merged, and many teams use them for object shapes; type is needed for unions like 'admin' | 'editor'. Using another language? Try JSON to Python, JSON to Java, JSON to Kotlin, JSON to Swift or JSON to Rust.
Frequently Asked Questions
What does JSON to TypeScript do?
It reads sample JSON and writes TypeScript interfaces that describe it, with the right types for strings, numbers, booleans, arrays and nested objects.
How are nested objects handled?
Each nested object gets its own named interface, based on its key name. For example a key called address becomes an Address interface.
What about fields that are missing in some items?
When an array has objects with different keys, keys that do not appear in every item are marked optional with a question mark.
Is my JSON sent to a server?
No. The interfaces are generated in your browser. Your JSON is never uploaded.