JSON to TypeScript Interface Generator
Turn a sample JSON object into TypeScript interfaces or type aliases.
About this tool
Paste a sample JSON object or array and get matching TypeScript interface declarations (or type aliases), including nested objects and arrays. This saves the tedium of hand-writing types for an API response or config file you already have real data for.
Types are inferred from a single sample — if a field is sometimes a different type or missing in other real responses, double-check the generated type against your actual data. The result is syntax-highlighted (toggle "Raw" for a plain copyable textarea); everything runs locally in your browser.
Example
{
"id": 42,
"name": "Ada",
"active": true,
"roles": ["admin", "staff"],
"profile": { "city": "London", "verified": false }
} interface Root {
id: number;
name: string;
active: boolean;
roles: string[];
profile: Profile;
}
interface Profile {
city: string;
verified: boolean;
} Nested objects are pulled out into their own named interface; arrays become T[].
Frequently asked questions
- How are arrays typed?
- An array of objects is merged into one nested interface using the union of keys seen across its elements — keys not present in every element are marked optional (
?). An array of primitives (numbers, strings) becomestype[], or a union like(string | number)[]if the values are mixed. - What happens with
nullvalues? - A field that is
nullin your sample is typed asnull— you'll likely want to widen it manually to something likestring | nullonce you know the field's real type from other samples. - Why does a property name have quotes around it in the output?
- JSON keys that aren't valid TypeScript identifiers (containing spaces, starting with a digit, etc.) are automatically wrapped in quotes, since TypeScript requires that for such property names.
- Is my JSON uploaded anywhere?
- No — parsing and type generation both happen entirely in your browser.