Convert any JSON object to TypeScript interfaces instantly. Handles nested objects, arrays and optional fields.
This free tool converts any JSON object into TypeScript interface definitions, recursively handling nested objects and arrays. Paste a JSON API response and instantly get a typed interface ready to drop into your TypeScript project - all generated in the browser, no data sent to any server.
Paste your JSON object into the input panel on the left and click Convert (or press Ctrl+Enter). The generator produces TypeScript interface definitions for the root object and all nested objects, with inferred types for every field. Copy the output and paste it directly into your TypeScript project. The entire conversion runs in your browser with no data sent to any server - safe for use with API payloads from private systems or client projects.
The generator maps JSON types to TypeScript as follows: JSON strings -> string, numbers -> number, booleans -> boolean, null -> null, arrays -> typed arrays (e.g. string[] or Item[] for object arrays), and nested objects generate their own named interfaces. The root object is named Root and nested objects take the name of their parent key with a capitalised first letter. You can rename these interfaces after copying the output.
Typing API responses gives you full IntelliSense autocomplete in VS Code and other IDEs, catches property name typos and wrong type assumptions at compile time rather than runtime, and makes refactoring safer - if an API field changes name or type, TypeScript immediately highlights all affected code. Without types, API data is treated as any in TypeScript, bypassing the type checker entirely. Typing even a single frequently-used API response can prevent entire categories of runtime bugs in frontend applications.
Both interface and type can describe the shape of an object in TypeScript. Interfaces are extendable with extends and can be re-opened (declaration merging), making them preferable for public API types that consumers may need to augment. Type aliases are more flexible - they can represent unions, intersections, and primitive types that interfaces cannot. For JSON object types, both work identically; this generator uses interface which is the conventional choice for data shape definitions in most TypeScript style guides.
The generator creates required fields for all keys present in the JSON sample. If some fields may be absent in real API responses, add the optional modifier ? manually: change email: string; to email?: string;. You can also use a union type to allow null: email: string | null;. For production use, consider validating at runtime using a library like Zod, which can both define the TypeScript type and validate the actual data structure, catching any discrepancies between the schema and the API response.