JSON to TypeScript Interface Generator
Paste any JSON and instantly get TypeScript interface definitions. Supports nested objects, arrays, null values, optional fields, and export keyword.
TypeScript interfaces will appear here…What the generator does
Paste a JSON sample — usually a response you just copied out of the network tab — and it walks the structure and emits one type per object it finds. Output updates as you type, and nothing is sent anywhere.
- interface or type — switch the output between an
interfaceblock and atypealias. - Root name — rename the top-level type; nested names are derived from their keys.
- Optional fields — add
?to every property. - Export types — prefix each declaration with
export, on by default. - Format JSON — re-indent the input in place, handy after pasting a minified payload.
- Counters and errors — how many types were generated and how many lines, or the parser error if the JSON is invalid.
Example: JSON in, interfaces out
JSON input
{
"id": 1,
"name": "Alice",
"profile": {
"age": 30,
"bio": null
},
"tags": ["admin"]
}TypeScript output
export interface Root {
id: number;
name: string;
profile: Profile;
tags: string[];
}
export interface Profile {
age: number;
bio: string | null;
}How each JSON value is typed
| JSON | TypeScript | Note |
|---|---|---|
| "Alice" | string | Dates are strings too — JSON has no date type |
| 30 / 9.99 | number | No int/float split in TypeScript |
| true | boolean | — |
| null | string | null | The string half is a guess; correct it if needed |
| ["a", "b"] | string[] | Element type taken from the values present |
| [1, "a"] | (number | string)[] | Mixed arrays become a union |
| [] | unknown[] | Nothing to infer from |
| { ... } | Named interface | Named after the key, in PascalCase |
interface or type alias?
For plain data shapes off an API, either is fine and the generated code is equivalent. interface supports declaration merging and reads conventionally for object shapes, which is why it is the default here. type is what you want if the shape will end up in a union, an intersection, or a mapped type — you cannot write type Result = Ok | Err with an interface.
Limitations worth knowing
Types are inferred from one sample, so the output is a starting point to review, not a contract. Specifically:
- Root arrays sample the first element only. If item 1 has fields that item 2 lacks, the generated type will be wrong for item 2.
- Nulls guess string. A field that is
nullin your sample but a number in production comes out asstring | null. - Same key name, same type name. Two different objects both under a key called
datacollapse into one interface, generated from whichever appeared first. - No literal or enum narrowing. A status field reading
"active"becomesstring, not a union of the allowed values. - Nothing is validated at runtime. If you need the shape checked against real responses, describe it with JSON Schema instead.
Related JSON & TypeScript tools
Frequently Asked Questions
How are TypeScript types inferred from JSON?
Each value is inspected and mapped to the nearest TypeScript type: strings to string, numbers to number, booleans to boolean, arrays to T[], and objects to their own named interface. Nesting is handled recursively.
What happens to null values?
A null becomes string | null. JSON gives no clue what the field holds when populated, so string is a guess — change it if the real type is a number or an object.
Does the Optional fields toggle only mark fields that were missing?
No. It adds ? to every field at once. It is a fast way to model a partial API response, not per-field inference, so trim the ones you know are always present.
Can it handle deeply nested JSON?
Yes, at any depth. Each nested object becomes its own interface named after its key in PascalCase, so a key called address produces an Address interface.
Does it handle arrays correctly?
Single-type arrays give T[], mixed arrays give a union like (string | number)[], and empty arrays give unknown[]. If the root itself is an array, only the first element is sampled.