JSON to TypeScript
Paste a JSON sample — such as an API response — to generate matching TypeScript interfaces.
Generate TypeScript types from JSON
Writing interfaces by hand for a large API response is slow and easy to get wrong. Paste a real response here and you get a set of export interface declarations you can drop into your project: one for the root object and one for each nested object, named after its key.
Arrays of objects are merged, so a field that appears in only some items is marked optional with ?, and a field that holds different types becomes a union such as string | number. Tick the option to get type aliases instead of interfaces.
Example
JSON input (root name set to User):
{
"id": 42,
"name": "Sara Khan",
"roles": ["admin", "editor"],
"address": { "city": "Lahore", "zip": "54000" },
"orders": [
{ "id": 1, "total": 19.99 },
{ "id": 2, "total": 5, "coupon": "WELCOME" }
],
"deletedAt": null
}TypeScript output:
export interface Address {
city: string;
zip: string;
}
export interface Order {
id: number;
total: number;
coupon?: string;
}
export interface User {
id: number;
name: string;
roles: string[];
address: Address;
orders: Order[];
deletedAt: null;
}Note how coupon became optional because only one order has it, and orders got its own Order interface.
Frequently asked questions
- Why is a field typed as null?
- The type is inferred from the sample you paste. If a field is null in every sample, its real type cannot be known — change it to something like string | null by hand, or paste a sample where it has a value.
- How are arrays handled?
- All items of an array are combined. Arrays of strings become string[], arrays of objects get their own interface, and mixed arrays become a union like (string | number)[].
- Interface or type — which should I use?
- Both work for describing JSON. Interfaces can be extended and merged; type aliases can express unions. Many teams default to interfaces for object shapes.
- Is my JSON uploaded anywhere?
- No. Everything runs in your browser, so API responses with real data never leave your computer.