JSON to TypeScript Interface Generator
Paste any JSON object or API response and get a fully typed TypeScript interface in one click — nested objects, arrays, optional fields, and union types all handled automatically.
interface Address {
city: string;
pincode: string;
country: string;
}
interface Root {
id: number;
name: string;
email: string;
isActive: boolean;
score: number;
address: Address;
tags: string[];
lastLogin?: null;
}Why convert JSON to TypeScript interfaces?
TypeScript's value is in catching type errors at compile time rather than runtime. But when you consume a REST API, a Firestore document, or a third-party SDK response, you typically get raw JSON with no type information. Without defining interfaces, you're back to any — and with any, TypeScript can't help you.
Manually writing interfaces for deeply nested API responses is tedious and error-prone. Miss one field, get the type wrong on another, and TypeScript will pass bad code straight through. A generator that reads your actual JSON and infers the shape is more reliable than typing it by hand.
This tool converts any valid JSON — objects, arrays, nested structures — into clean, well-named TypeScript interfaces. It handles the repetitive work so you can focus on using the types, not defining them.
How to generate TypeScript interfaces from JSON
- 1
Paste your JSON
Copy a sample API response or any JSON object and paste it into the left editor. Invalid JSON is flagged immediately.
- 2
Name the root interface
Set the name for the root interface (default: Root). Nested objects get automatically named based on the key.
- 3
Copy the output
The generated TypeScript appears on the right. Click Copy to grab it and paste it directly into your .ts file.
- 4
Review and refine
Check optional fields (marked with ?) and union types. Widen types where the sample may not cover all cases.
Why developers use this tool daily
Type API responses in seconds
Stop writing interfaces by hand. Paste the response from Postman or DevTools and get a typed interface instantly.
Catch field name typos
The generator uses your actual JSON keys — no more mistyped field names that only fail at runtime.
Handle deeply nested data
Recursive type generation means even 5-level-deep JSON structures produce clean, named interfaces for every level.
Accelerate onboarding
New team members can understand an unfamiliar API's data shape at a glance by reading the generated interfaces.
Examples
{"id":1,"name":"Priya Sharma","email":"priya@example.com","isActive":true}interface Root {
id: number;
name: string;
email: string;
isActive: boolean;
}Simple objects map 1:1 — each key becomes a typed field.
{"user":{"id":42,"name":"Rahul"},"posts":[{"id":1,"title":"Hello World","published":true}]}interface User {
id: number;
name: string;
}
interface Post {
id: number;
title: string;
published: boolean;
}
interface Root {
user: User;
posts: Post[];
}Nested objects and arrays get their own named interfaces, derived from the parent key name.
How the type inference works
The generator walks the JSON tree recursively. For each key-value pair, it maps the JavaScript value type to a TypeScript type: string, number, boolean, null. Nested objects become named sub-interfaces (the key name is PascalCased and used as the interface name). Arrays are typed as T[] where T is inferred from the first element.
When an array contains mixed types (e.g. [1, "two", null]), the generator produces a union type: (number | string | null)[]. Fields that appear in some samples but not others should be marked optional (?) — the generator marks fields as optional when their value is null or undefined in the provided sample.
interface vs type alias — which to use?
- interface is the standard for describing the shape of an object. It supports declaration merging (you can extend it in multiple places) and produces cleaner error messages. Prefer
interfacefor objects. - type is more flexible — it can describe primitives, unions, intersections, and tuples, not just objects. Use
typewhen you need a union of several interfaces or a mapped type. - For most API response shapes,
interfaceis the right default. The toggle in this tool lets you switch between both styles instantly.
After generating — what to do next
- Move the generated interfaces into a dedicated
types/orinterfaces/directory so they are importable across your codebase. - Add JSDoc comments to document what each field represents — the generator cannot infer semantics, only shape.
- For strictly-typed API calls, use the interface as a generic constraint:
axios.get<UserResponse>('/api/user'). - Consider using
zodorvalibotalongside TypeScript interfaces for runtime validation — interfaces only exist at compile time and are erased from the JavaScript bundle.
Frequently asked questions
Yes. The generator is recursive with no hard depth limit. Very large JSON (thousands of keys) may take a moment but will produce complete output.
Null values are typed as null. If a field could be either a string or null, you should manually change the type to string | null after generation. Always validate your sample covers all possible values.
An empty array ([]) has no element to infer from, so it defaults to any[]. Similarly, if the JSON contains a value type the generator cannot map (extremely rare), it falls back to any. In both cases, manually specify the correct type after copying the output.
Yes. If your JSON root is an array (e.g. [{...}, {...}]), the generator infers the element type and produces a RootItem interface, with the root type being RootItem[].
quicktype is a more comprehensive tool that supports multiple target languages and handles multiple JSON samples. This tool is lighter, faster, browser-native, and focused specifically on TypeScript — no installation, no configuration.
Not directly — zod schemas and TypeScript interfaces are two different things. However, you can use the generated interface as a reference to write a matching zod schema manually, or use tools like zod-to-ts (zod schema → TypeScript type) or ts-to-zod (TypeScript → zod schema) to automate the conversion.
Need another tool?
Browse the full toolbox or dig into the blog for the engineering behind it.