JSON to TypeScript
Generate TypeScript interfaces from any JSON — instantly and locally.
Paste any JSON and get clean TypeScript interfaces back — nested objects, arrays, optionals and unions inferred automatically, all in your browser. Free. No sign-up. Runs in your browser, nothing is uploaded.
TypeScript interfaces
Your generated TypeScript interfaces will appear here.Types are inferred locally in your browser. Your JSON is never uploaded.
Paste a JSON sample and the TypeScript appears as you type: every nested object becomes its own named interface, arrays get element types, keys missing from some records become optional, and nulls turn into | null unions. Set the root interface name to something meaningful such as User or OrderResponse, press Copy, and paste the result into your types.ts. Sample loads a nested example if you want to see the output first.
What a real API list turns into
Paste a list of two users from an endpoint, with the root name set to User:
[
{ "id": 1, "name": "Ada", "deletedAt": null, "roles": ["admin"] },
{ "id": 2, "name": "Linus", "deletedAt": "2026-01-01", "roles": ["dev"], "nickname": "lt" }
]
and you get:
interface UserItem {
id: number;
name: string;
deletedAt: string | null;
roles: string[];
nickname?: string;
}
type User = UserItem[];
Because the top level is an array, the root name goes to a type alias for the list and the element interface gets an Item suffix. Rename UserItem to User and the alias to Users if that reads better in your code — it usually does.
How each JSON value becomes a type
| In the JSON | In the TypeScript | Note |
|---|---|---|
"text" | string | Dates and IDs in strings are string too |
42, 3.14 | number | No distinction between integers and decimals |
true | boolean | |
null | null | Joined with other types: string | null |
{ … } | a named interface | Declared separately, referenced by name |
["a", "b"] | string[] | Repeated types are collapsed, not listed ten times |
[1, "a", null] | (number | string | null)[] | Mixed arrays become a union in brackets |
[[1, 2]] | number[][] | Nesting is preserved |
[{…}, {…}] | Item[] with one merged interface | Keys missing in some objects get ? |
[] | unknown[] | Nothing to infer from |
If the top level of your JSON is an array, the root name becomes a type alias for the list; a top-level string or number becomes a simple alias such as type Root = string;. Interfaces for nested objects are listed before the ones that use them, so the output reads from the leaves up.
How the names are chosen
- Nested objects are named after their key in PascalCase:
billingAddressbecomesBillingAddress. - Array elements are named after the singular of their key:
orders→Order,categories→Category,addresses→Address. Words that only look plural, such asstatus,newsorseries, are left alone. - Keys that are not valid identifiers are quoted:
"first-name": string;. - Name clashes get a number: a second, differently shaped
addressobject becomesAddress2.
Where you will want to tidy up
Inference describes the sample you paste, nothing more. These are the spots to check before committing the types:
- Nested objects across list items are not merged. If two records each have an
addressobject, you getAddressandAddress2and the field becomesAddress | Address2— even when both have exactly the same fields. Delete the duplicate interface, or merge the two into one with the differing fields marked optional (zip?: string). - An empty array in one record leaks
unknown[]into the union:tags: string[] | unknown[]. Shorten it tostring[]. - Strings hide enums. A
statusthat is always"paid","open"or"refunded"comes out asstring. Replace it with"paid" | "open" | "refunded"if the API documents a fixed set. - Numbers hide meaning. IDs, Unix timestamps and prices are all
number. Add your own type aliases (type UserId = number) where mixing them up would be a bug. - Dates are strings. JSON has no date type, so
"2026-01-01"isstring. Parse it into aDateat the boundary of your app, not in the type. - Fields your sample never shows do not exist in the output. A single response rarely contains every optional field; check the API documentation for the rest.
- Mixed arrays become unions such as
(string | number)[]. Sometimes that is real; sometimes it is one bad record worth reporting upstream.
Getting the best sample
- Paste a list, not a single item. Optional fields can only be detected by comparing records; ten varied rows beat one.
- Include a record where nullable fields are actually null, so the type forces your code to handle the empty case.
- Keep the envelope. For paginated endpoints, paste the whole response (
data,meta,links) so the wrapper is typed too, then refine the inner item interface. - Trim huge payloads. A 5,000-element array gives the same result as twenty representative elements, and is far easier to read in the editor.
If the response comes back minified, tidy it in the JSON Formatter first to read its shape. To get the same records into a spreadsheet instead, send them through the JSON ↔ CSV Converter.
