JSON to TypeScript Interface Generator
Paste JSON to generate matching TypeScript types, including nested objects and arrays.
Output Settings
How to use this tool
Paste a real response or config file, not one you typed from memory, since the types can only be as good as the sample. Set the root type's name, then choose interface or type, whether every field should be optional, and whether nested objects become separate named types or are written inline.
Worked example: an array of orders
{
"orders": [
{ "id": 1, "total": 499, "coupon": "DIWALI10" },
{ "id": 2, "total": 1299 },
{ "id": 3, "total": 899, "note": null }
],
"addresses": [{ "city": "Pune" }],
"meta": {}
}interface Root {
orders: Order[];
addresses: Address[];
meta: Meta;
}
interface Meta {
[key: string]: unknown;
}
interface Address {
city: string;
}
interface Order {
id: number;
total: number;
coupon?: string;
note?: null;
}The three orders are merged into one Order type. coupon and note appear in only some of them, so they are marked optional. Array fields are named after one element: orders gives Order, addresses gives Address. The empty meta object says nothing about its keys, so it accepts any key with an unknown value.
What to fix by hand afterwards
- Fields that were null in the sample get the type
null, likenoteabove. Replace it with the real type, such asstring | null. - Fixed sets of values come out as
string. Ifstatuscan only be "paid", "pending" or "refunded", write that union yourself. - Dates in JSON are strings, so they stay
stringuntil your code turns them into Date objects. - Empty arrays become
unknown[], because there is no element to learn from.
Frequently Asked Questions
Should I use "interface" or "type"?
For most object shapes, they're functionally interchangeable. interface is generally preferred by convention for object shapes that might be extended or implemented (matching common TypeScript style guides), while type is required for unions, intersections, and other non-object type constructs. This tool lets you generate either, since teams differ on which they standardize on.
What happens to an array with mixed values, like [1, "n/a", 2]?
Every element is checked, and the type lists each kind that appears: (number | string)[]. Objects in the same array are merged into a single type rather than one type per element, and arrays of arrays become types such as number[][].
Why are some keys in quotes?
A key that isn't a valid JavaScript identifier, such as "order-id" or "2fa_enabled", has to be quoted in a TypeScript type. You then read it with brackets, order["order-id"], rather than a dot.
Related Tools
Related Blog Posts
How to Use QR Codes for Marketing, Docs, and Events
How much a QR code can hold, why a shorter or uppercase link gives a code that scans more easily, what error correction actually protects against, and how to size one for print.
Read moreHEX, RGB and HSL: How the Conversions Work and Where They Round
#4F46E5 converted to RGB and HSL step by step, why 89.4% of all colours change when copied as whole-number HSL, why HSL lightness is not brightness (yellow and blue at 50% differ eightfold in contrast), and the alpha that hex can't write exactly.
Read more10 CSS Gradient Ideas You Can Copy and Customize
Ten copy-ready CSS gradients (buttons, dark surfaces, progress bars, stripes, glows, gradient text, photo overlays), plus how gradient angles work and how to avoid the muddy grey middle.
Read more