JSON to TypeScript Interface Generator
Paste a JSON sample and get TypeScript interfaces: nested objects become named interfaces, keys missing from some items become optional, and null values become union types.
JSON to TypeScript
Runs in your browser — nothing you enter is uploaded or stored.
Scratchpad auto-saved
How it works — in four simple steps
No signup and nothing to install — it all runs in your browser.
Add your JSON
Paste it into the left box, press Open file, or drag a .json file onto it. Sample loads a realistic example.
Set the options
Adjust the options above the boxes — the output updates instantly as you change them.
Check the result
Read the status line: it reports rows, keys and any value that couldn't be represented in TypeScript.
Copy or download
Copy the TypeScript or download it as a .ts file. Nothing was uploaded at any point.
Paste several records, not one: optional keys and null unions are inferred across all of them.
Features
Named types
Choose the root type name; nested objects become their own named types, and identical shapes are merged.
interface or type
Generate interface declarations or type aliases, optionally exported and readonly.
Private by design
Parsing and conversion run in your browser with JavaScript — your data is never uploaded, logged or stored.
About the JSON to TypeScript
Typing an API response by hand is slow and error-prone. This generator infers types from real data. It walks the JSON, and for every object it creates a named interface — the root is Root (or the name you choose), a nested address object becomes Address, and objects inside a books array become Book (singularised). Objects with exactly the same fields share one interface instead of producing duplicates.
Arrays are analysed across all their elements, which is what makes the result trustworthy: if one item has a discount key and another doesn't, the field is generated as discount?: number; if a value is sometimes null it becomes number | null; if it's sometimes a string and sometimes a number it becomes string | number. Keys that aren't valid identifiers ("first-name") are quoted. Integers and floats are both number, as in TypeScript.
Choose interfaces or type aliases, toggle export, or make every property readonly for immutable data. Paste a few representative records rather than one — more samples give more accurate optional and union types.
Examples
Two user records from an API: one has an optional field the other lacks, one value is null, and each has a nested object and a list of objects.
[
{ "id": 1, "name": "Ada", "email": "ada@example.com", "team": { "id": 10, "name": "Core" }, "roles": [{ "id": 1, "label": "admin" }], "lastLogin": "2026-10-20T09:00:00Z" },
{ "id": 2, "name": "Alan", "email": "alan@example.com", "team": { "id": 11, "name": "Data" }, "roles": [], "lastLogin": null, "nickname": "Prof" }
]export interface User {
id: number;
name: string;
email: string;
team: Team;
roles: Role[];
lastLogin: string | null;
nickname?: string;
}
export interface Team {
id: number;
name: string;
}
export interface Role {
id: number;
label: string;
}
export type UserList = User[];This output was produced by the converter on this page with root name User — load it with the “API users” preset above and change any option to see the effect.
How JSON maps to TypeScript
| In JSON | Becomes in TypeScript |
|---|---|
"name": "Ada" | name: string; |
"age": 36 / 36.5 | age: number; |
Nested object address | address: Address; + interface Address |
"tags": ["a"] | tags: string[]; |
| Key missing in some items | discount?: number; |
Sometimes null | number | null |
"first-name" | "first-name": string; |
| Top-level array | type RootList = Root[]; |
Things that trip people up
- Types come from the sample. A field that's always null in your sample becomes
null; one that's an empty array becomesunknown[]. Paste a richer sample or edit those by hand. - Dates are strings. JSON has no date type, so ISO dates are typed as string. Convert them in your code, or change the type to a branded string.
- Enums aren't guessed. A status field with values like "open" | "closed" is typed string. Narrow it to a union of literals if the set is fixed.
- Runtime safety. Interfaces don't validate data at runtime. Pair them with a JSON Schema (see the generator) or a validator such as Zod for untrusted input.
JSON vs TypeScript at a glance
| Property | JSON | TypeScript |
|---|---|---|
| Specification | RFC 8259 (2017) · ECMA-404 | TypeScript 5.x |
| File extension | .json | .ts |
| Media type | application/json | text/plain |
| Data types | string, number, boolean, null, object, array | string, number, boolean, null, arrays, unions |
| Comments | No | Yes |
| Nesting | Unlimited | Named interfaces |
- JSON: Numbers are parsed as IEEE-754 doubles in JavaScript, so integers above 9,007,199,254,740,991 (2⁵³ − 1) lose precision.