JSON to TypeScript Generator

Convert JSON objects to TypeScript interfaces instantly. Supports nested objects and arrays.

export interface Root { id: number; name: string; email: string; active: boolean; score: number; tags: string[]; address: Address; } export interface Address { street: string; city: string; zip: string; }

About the JSON to TypeScript Generator

The JSON to TypeScript Generator converts any JSON object or array into fully typed TypeScript interface definitions. Paste your JSON, set the root interface name, and get copy-ready TypeScript types in one click. Nested objects are automatically extracted into their own named interfaces; arrays are typed based on the first element.

TypeScript interfaces are the standard way to describe the shape of data in TypeScript projects. When working with REST APIs, the response body is often JSON — manually writing interfaces for it is tedious and error-prone. This tool eliminates that work: paste the API response and immediately get a correctly typed interface that you can drop into your codebase.

All conversion runs entirely in your browser — no JSON data is sent to any server. The output is valid TypeScript and can be downloaded as a .ts file. For production use, review the generated types and add JSDoc comments where needed.

Frequently Asked Questions

What is a TypeScript interface?

A TypeScript interface defines the shape of an object — the names and types of its properties. Unlike classes, interfaces are erased at compile time and have no runtime cost. They are used to type-check objects throughout your code and provide autocomplete in editors.

How are nested JSON objects handled?

Each nested object is extracted into its own interface with a name derived from the parent key (converted to PascalCase). For example, a key "address" with an object value generates an Address interface and types the field as address: Address.

How are JSON arrays typed?

Arrays are typed based on the first element. If the first element is an object, that object is used as the array item interface. An empty array is typed as unknown[] since the element type cannot be inferred.

What does "mark null fields optional" do?

When enabled, any field whose value is null or undefined in the JSON is marked as optional (field?: type) in the generated interface. This is useful when some fields may be absent in real API responses.

Should I use interface or type?

interface is preferred for describing object shapes — it supports declaration merging and is more idiomatic. type is more flexible (it can describe unions, intersections, and primitives) but cannot be merged. For JSON API types, interface is the standard choice.