JSON to TypeScript
This tool reads a JSON sample, such as an API response, and writes TypeScript interfaces that describe it. Front-end and Node.js developers use it to type fetch results and config objects without writing every field by hand.
- Runs in your browser
- Free, no account needed
- Copy or download the result
Result
The short answer
TypeScript describes the shape of data with types, and JSON values map to them directly: strings to string, numbers to number, true and false to boolean, arrays to T[], and nested objects to their own interfaces. A field present in only some array items becomes optional with a question mark.
Formulastring to string, number to number, boolean to boolean, null to null, array to T[], object to interface, field missing in some items to name?
Worked exampleThe sample user becomes an interface User with id number, name string, email null, tags string[], address Address and orders Order[]; Order marks coupon as optional (coupon?: string) because only the second order has one.
Example
{"id":42,"name":"Ada","email":null,"tags":["admin","dev"],"address":{"city":"London","zip":"NW1"},"orders":[{"id":1,"total":19.99},{"id":2,"total":5,"coupon":"SPRING"}]}export interface User {
id: number;
name: string;
email: null;
tags: string[];
address: Address;
orders: Order[];
}
export interface Order {
id: number;
total: number;
coupon?: string;
}
export interface Address {
city: string;
zip: string;
}How to use the json to typescript
- Paste a JSON sample into the JSON sample box.
- Set the Root type name, such as User.
- Pick Declare as: interface or type.
- The result updates as you type (Run also works). Use Copy result or Download to save it.
How it works
Each nested object gets its own exported declaration, named from its key in PascalCase. Array items get a singular name, so orders becomes Order.
All objects in an array are merged into one shape. A field missing from some of them is marked optional with ?, and a field with different kinds of values becomes a union such as string | number.
null values add | null, empty arrays become unknown[], and empty objects become Record<string, unknown>.
Keys that are not valid identifiers, such as my-key, are written in quotes. Objects with exactly the same fields share one declaration.
The types describe only your sample, so check optional fields and unions against your real data.
Everything runs in your browser. Your input is not uploaded or stored. If you use Copy link, what you entered is placed in the link.
Questions and answers
Should I use interface or type?
Both work for object shapes. Interfaces can be extended and merged later, while type aliases are often preferred for unions. Pick the style your project already uses.
Why is a field marked optional?
At least one object in an array did not have that field, so the generated type allows it to be missing.
Does it detect dates or enums?
No. JSON has no date type, so dates are typed as string, and repeated text values are not turned into enums.
Is my JSON uploaded?
No. It runs in your browser, and nothing you paste is sent to a server.
Last updated November 1, 2026. Maintained by SnowRock. How our tools work
All 220 SnowRock tools