What this does
Paste an API response or config file and get TypeScript interfaces that describe it. Nested objects become their own named interfaces, arrays become T[], and a field that is missing from some objects in an array is marked optional with?. A top-level array works too: the element objects are merged into one interface.
Example
Input
{
"id": 42,
"name": "Ada",
"verified": true,
"tags": [
"admin",
"dev"
],
"orders": [
{
"sku": "A1",
"qty": 2
},
{
"sku": "B2",
"qty": 1,
"note": "gift"
}
]
}Output with default options
export interface Root {
id: number;
name: string;
verified: boolean;
tags: string[];
orders: Order[];
}
export interface Order {
sku: string;
qty: number;
note?: string;
}
Options
- Type name: the name of the root interface (default
Root). - Types only: on by default, which gives plain declarations. Turn it off to also get a
Convertclass with runtime-checked JSON parsing helpers. - Type aliases switches
interface Foo {}totype Foo = {}; Readonly addsreadonlyto every property. - Detect dates and UUIDs types ISO 8601 strings as
Date. Turn it off to keep them asstring, which matches whatJSON.parseactually returns.
Things to know
The types are inferred from the sample you give, so they are only as complete as that sample: a field that is always present in your sample will be required, and a field that isnull everywhere becomes null. Feed it several representative objects in an array to get realistic optional fields. Mixed arrays becomeArray<number | string>. If you need validation at runtime, use theJSON to Zod converter instead.
Privacy
Generation runs in a Web Worker in your browser. The JSON is never uploaded.