JSON to TypeScript interface
The tool reads a JSON sample and writes one interface per object, so you do not have to type API response shapes by hand.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter json input and root type name.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
string for text, number for every number, boolean for true/false, T[] for lists, and each nested object becomes its own interface. When array items are merged, a key missing from some items becomes optional (?), null adds | null, and a key that is only ever null becomes unknown.
Example
Inputs: Root type name = Root. Result: Generated code: export interface Root { id: number; name: string; email: string; is_active: boolean; balance: number; tags: string[]; address: Address; orders: Order[]; } export interface Address { city: string; postal_code: string; } export interface Order { order_id: string; total: number; coupon: string | null; }; Types generated: 3; Fields: 13.
{
"id": 1024,
"name": "Sara Ahmed",
"email": "sara@example.com",
"is_active": true,
"balance": 1520.75,
"tags": ["vip", "riyadh"],
"address": { "city": "Riyadh", "postal_code": "12211" },
"orders": [
{ "order_id": "A-1", "total": 99.5, "coupon": "EID10" },
{ "order_id": "A-2", "total": 120, "coupon": null }
]
}export interface Root {
id: number;
name: string;
email: string;
is_active: boolean;
balance: number;
tags: string[];
address: Address;
orders: Order[];
}
export interface Address {
city: string;
postal_code: string;
}
export interface Order {
order_id: string;
total: number;
coupon: string | null;
}Limits and caveats
- Types come from the sample only, so a key that never appears is not generated.
- A key holding different types, such as text in one item and a number in another, becomes unknown.
Questions about this tool
How are arrays of objects handled?
All items are merged into one type. A key that appears in only some items becomes optional with ?.
Why are some keys in quotes?
A key with a dash or space, or one that starts with a digit, is not a valid TypeScript identifier, so it is written like "full-name".
Is my JSON sent to a server?
No. The conversion runs in your browser and the JSON never leaves your device.
