JSON to TypeScript
Paste an API response and get TypeScript interfaces for it. Nested objects get their own named types.
JSON sample
TypeScript
How to use it
- 1Paste a JSON sample, ideally a real response with all fields present.
- 2Set the root type name and choose interface or type alias.
- 3Copy the result into your project and adjust names or literal types as needed.
Private by design
Everything runs in this browser tab. Your input is never uploaded, logged or saved on a server, and there are no public "recent" pages. Close the tab and it's gone.
How we keep it privateExamples
Fields missing from some items become optional (?).
Input
{"users": [{"id": 1, "name": "Ada"}, {"id": 2, "email": null}]}Output
export interface Root {
users: User[];
}
export interface User {
id: number;
name?: string;
email?: null;
}How types are inferred
The generator reads your sample and applies a few simple rules:
- Every object becomes a named interface; its name comes from the key (address → Address, line_items → LineItem).
- Objects inside one array are merged into one type. A field missing from some of them is marked optional.
- Mixed values become unions, e.g. (number | string)[]. null in the sample becomes | null.
- Empty arrays become unknown[], since the sample doesn’t say what they hold.
- Keys that aren’t valid identifiers are quoted: "total-count": number.
Make the sample count
The types can only be as good as the sample. Use a response where optional fields are filled in, and include several array items when they differ. For strict runtime checks, pair these types with a schema validator such as Zod.
Frequently asked questions
Interface or type: which should I choose?
Both work for object shapes. Interfaces can be extended and merged; type aliases can express unions. Many codebases use interfaces for API data, which is the default here.
Are dates typed as Date?
No. JSON has no date type, so ISO date strings are typed as string, which is what JSON.parse gives you at runtime.
Is my JSON uploaded?
No. Types are generated in your browser. Nothing is sent or stored.