JSON to TypeScript Interface Generator
Paste JSON and get TypeScript interfaces or types with nested objects, arrays and optional fields. Free, fast and runs in your browser.
Runs in your browser. Nothing is uploaded.
Example
Input:
{"id": 1, "name": "Asif", "tags": ["node"], "address": {"city": "Lahore"}}Result:
export interface Root {
id: number;
name: string;
tags: string[];
address: Address;
}
export interface Address {
city: string;
}What this generator does
Paste a JSON document, such as an API response, and the tool infers a TypeScript type for it. Nested objects become their own named interfaces, arrays become typed arrays, and values that are null or missing in some array items become optional or union types. You can switch between interface and type alias output and set the name of the root type.
The result is a starting point that saves typing when you wire a new endpoint into an Angular service or an Express handler. It describes the sample you pasted, so review it before committing.
How types are inferred
Strings, numbers and booleans map directly. null becomes null. For arrays, every item is merged into one shape: a key that appears in only some objects becomes optional (name?: string), and different primitive types become a union such as string | number. An empty array becomes unknown[] because there is nothing to infer from. Object keys that are not valid identifiers, such as "first-name", are quoted.
Nested objects are named after their key in PascalCase, so an "address" field produces an Address interface and an array called "items" produces an Item type for its elements. When two different objects would get the same name, a number is added (Address2) so nothing is silently overwritten. Rename them afterwards to match your domain language; the structure is what matters.
Why a sample is not a contract
A single response cannot show every shape an API may return: a field that was always present in your sample may be absent in production, and a number may sometimes be a string. For data that crosses a trust boundary, pair the generated type with runtime validation, for example a Zod schema in your Express API, so the TypeScript type and the real data cannot drift apart. Use this tool to get the first draft quickly, then tighten it.
Frequently asked questions
How does it decide a field is optional?
When you paste an array of objects, a key that is missing from some items is marked optional with a question mark.
Should I use interface or type?
Both work for object shapes. Interfaces can be extended and merged; type aliases can also express unions. The tool lets you pick either.
Can I trust the generated types for API data?
Treat them as a draft from one sample. Validate untrusted data at runtime, for example with Zod, so the types match what the API really sends.
Is my JSON uploaded?
No. Everything runs in your browser.
