Generating TypeScript types from JSON
When you call an API from TypeScript, you want a type that describes its response, so the editor can autocomplete fields and the compiler can catch typos. Writing that interface by hand from a long JSON sample is slow and error-prone.
Paste a JSON sample and this tool writes the interfaces for you. Nested objects get their own named interfaces, arrays get element types, mixed values become union types, and when objects in an array differ, the fields that only some of them have are marked optional.
How to use it
- Paste a JSON response or document into the input box.
- Read the generated interfaces; the top-level type is always called Root.
- Rename Root and the nested interfaces to match your domain, for example User or Order.
- Copy the result into a .ts file and import it where you call the API.
Example: a nested API response
{"id":1,"name":"Ada","tags":["math"],"address":{"city":"London","zip":null}}export interface Address {
city: string;
zip: null;
}
export interface Root {
id: number;
name: string;
tags: string[];
address: Address;
}The address object becomes its own interface named after its key. The zip field was null in the sample, so its type is null; in real code you would widen it to string | null.
A sample is not a schema
The tool can only describe the JSON you give it. If a field happened to be null in your sample, the type says null; if an array was empty, its items are unknown. Paste a sample with realistic, filled-in values, or several array items that show the variations, and review fields that can be missing or null in practice.
Objects inside one array are merged into a single interface. A field that appears in some items but not in others becomes optional, marked with ?, which is usually exactly what a list of API records needs.
Types do not check data at runtime
TypeScript types disappear when the code is compiled, so they cannot stop a server from sending something different. For data from outside your control, validate at the boundary with a runtime schema library such as Zod or Valibot, and derive the type from the schema so the two never drift apart.
Naming
Interface names are built from the JSON keys in PascalCase: address becomes Address and shipping-info becomes ShippingInfo. Items of an array get the array's name plus Item, such as UsersItem. When two keys produce the same name, a number is added, like X2, so every interface stays unique. Keys that are not valid identifiers are kept in quotes.
Questions
Interface or type alias?
For object shapes both work. The tool writes interfaces, which give clearer error messages and can be extended. The root becomes a type alias only when the JSON is an array or a single value.
Can it detect dates?
No. JSON has no date type, so dates arrive as strings and are typed as string. Convert them in your code.
Is my JSON uploaded?
No. Everything runs in your browser, so API responses with real data stay private.