JSON → TypeScript
Generate TypeScript interfaces from JSON — nested types, unions, and optional fields. 100% local.
How Type Inference Works
The inferrer samples your JSON and produces the most specific TypeScript interface it can. Each key becomes a property. The value's runtime type determines the TypeScript type. For fields that are null in your sample, the inferrer produces T | null — meaning the field exists but may be null.
Input
{
"user": {
"id": 1,
"name": "Alice",
"email": "[email protected]",
"role": "admin",
"tags": ["typescript", "json"],
"address": {
"city": "London",
"country": "UK"
},
"metadata": null
},
"total": 42,
"active": true
}Output
export interface Root {
user: User;
total: number;
active: boolean;
}
export interface User {
id: number;
name: string;
email: string;
role: string;
tags: string[];
address: Address;
metadata: null;
}
export interface Address {
city: string;
country: string;
}Inference Rules
| JSON value | TypeScript type | Notes |
|---|---|---|
| "string" | string | Any string value |
| 42 or 3.14 | number | All JSON numbers become number |
| true / false | boolean | Boolean literal becomes boolean |
| null | null | Nullable — combine with | T if field also has non-null values |
| [1, 2, 3] | number[] | Homogeneous array infers element type |
| [1, "a", true] | (number | string | boolean)[] | Mixed array becomes union |
| {} or { ... } | Named interface | Nested objects become separate interfaces |
| [] (empty) | unknown[] | Empty array can't be inferred — annotate manually |
Tip: The root type name (configurable in the toolbar) becomes the name of the outermost interface. Nested objects are named by capitalizing their key name. For production code, review and adjust names like
Address or User to match your domain model.Limitations to Know
Warning: Inference is based on a single sample. If a field is
null in your sample but is sometimes a string in real data, you'll need to manually change null to string | null. Run the inferrer on a representative sample that covers all the shapes your data can take.Try It
Interactive — edit the input to see the output update
Try it
Result
Frequently Asked Questions
Your files stay on your computer. Dad promised.