JSON to TypeScript Interface
Paste a JSON sample and get TypeScript interfaces, with nested objects, arrays, optional fields and union types worked out for you.
Paste a JSON sample and get TypeScript interfaces, with nested objects, arrays, optional fields and union types worked out for you.
Writing TypeScript types for an API response by hand is slow. Paste a sample of the JSON and this tool infers the interfaces for you.
Nested objects become their own interfaces, arrays of objects are merged into one, fields that are missing in some items become optional, and mixed values become union types.
export interface User {
id: number;
name: string;
address: Address;
}
export interface Address {
city: string;
}
From the values in your sample. A sample cannot show every possible value, so review the result, especially for null and optional fields.
All objects in an array are merged into one interface. A property that is missing from some of them is marked optional.
They are quoted, for example "first-name": string.
No. It stays in your browser.