JSON to TypeScript
Generate TypeScript interfaces or types from JSON, with optional and nullable fields detected.
export interface Root {
id: number;
name: string;
email: string;
"is-verified": boolean;
address: Address;
orders: Order[];
}
export interface Address {
city: string;
pincode: string;
}
export interface Order {
orderId: string;
amount: number;
coupon: string | null;
giftWrap?: boolean;
}
JSON to TypeScript FAQ
How do I convert JSON to a TypeScript interface?
Paste the JSON into this page and set a Root type name. The interfaces appear at once; click Copy and paste them into a .ts file.
How are optional fields detected?
All items of an array are merged. If a key appears in some items but not in others, it is marked optional with ?. If it is null in some items, null is added to its type, for example string | null.
What is the difference between interface and type in TypeScript?
For object shapes both work the same in most code. Interfaces can be extended and merged; type aliases can also name unions and arrays. Root arrays and plain values always use type here, for example export type Root = RootItem[].
Why are some keys in quotes?
Keys such as first-name or 2fa are not valid TypeScript names, so they must be quoted to compile. You then read them as obj["first-name"].
Is my JSON sent to a server?
No. The types are generated in your browser, so your data stays on your device and nothing is saved.