Typed models from real data
Writing interfaces by hand for a large API response is slow and error-prone. This generator reads your JSON and produces TypeScript declarations that match it. Unlike simple converters that only look at the first element of an array, it merges every element: if a property exists in some objects but not others it becomes optional (archived?: boolean), and if a property holds different kinds of values it becomes a union (string | null).
Nested objects get their own named interfaces (derived from the property name, e.g. profile → Profile, projects → Project), and identical shapes are reused instead of being duplicated.
How to use it
- Paste a representative JSON sample — the more array items it contains, the more accurate the optional fields will be.
- Set the root type name, choose
interfaceortype, and toggleexport/readonly. - Copy the result into a
.tsfile or download it.
Example
JSON
{
"id": 1,
"tags": ["a"],
"items": [
{"sku": "A", "qty": 1},
{"sku": "B", "qty": 2, "note": "gift"}
]
}TypeScript
export interface Root {
id: number;
tags: string[];
items: Item[];
}
export interface Item {
sku: string;
qty: number;
note?: string;
}Type mapping
| JSON value | TypeScript type |
|---|---|
"text" | string |
42, 3.14 | number |
true | boolean |
null | null (combined into a union when other values exist) |
[] (empty) | unknown[] |
| object | a named interface |
Dates arrive in JSON as strings, so they are typed as string. Convert them to Date in your code if needed.
Frequently asked questions
Should I use interface or type?
Both describe object shapes. Interfaces can be extended and merged, which many teams prefer for API models; type aliases are needed for unions. Pick whichever matches your codebase style.
Why is a field typed as null?
Your sample only contained null for that field. Add a sample where it has a real value and the type becomes a union such as string | null.
Does it support property names with spaces or dashes?
Yes. Such keys are written in quotes, e.g. "first-name": string.
Is my JSON uploaded?
No. Generation happens in your browser.