JSON to TypeScript Interface Converter

Paste a JSON object and get TypeScript interface definitions with correctly inferred types. Handles nested objects, arrays, and all JSON data types.

Why Convert JSON to TypeScript Interfaces?

When you integrate an external API, the first thing you need is type definitions for the response data. Manually writing TypeScript interfaces from API documentation or sample responses is tedious and error-prone. You need to inspect every field, determine its type, handle optional values, and account for nested structures. This converter does all of that instantly.

TypeScript interfaces catch bugs at compile time that would otherwise surface as runtime errors. A mistyped property name, a number treated as a string, or a missing null check are all caught by the type checker if your interfaces are accurate. Starting from real JSON data ensures your interfaces match the actual API contract, not an outdated spec.

How the Converter Works

The converter recursively walks your JSON structure and infers TypeScript types from JavaScript runtime types:

For example, a JSON object with a nested "address" object generates both a Root interface and an Address interface, with the Root referencing Address by name.

Example

Input JSON

{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "active": true,
  "roles": ["admin", "editor"],
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "zip": "10001"
  }
}

Output TypeScript

interface Address {
  street: string;
  city: string;
  zip: string;
}

interface Root {
  id: number;
  name: string;
  email: string;
  active: boolean;
  roles: string[];
  address: Address;
}

Best Practices for TypeScript Interfaces

TypeScript Interface vs Type Alias

TypeScript offers two ways to define object shapes: interface and type. Interfaces are extensible (you can merge declarations and use extends), while type aliases are more flexible (they support unions, intersections, and mapped types). For API response objects, interfaces are the conventional choice because they clearly communicate "this is the shape of an object" and support declaration merging for module augmentation.

This converter generates interfaces because that is the idiomatic pattern for object shapes in TypeScript. If you need a type alias instead, simply replace interface Root with type Root = in the output.

Common Workflows

Frequently Asked Questions

How does JSON to TypeScript conversion work?

The converter parses your JSON, inspects each value's runtime type (string, number, boolean, array, object, null), and generates a TypeScript interface with the correct type annotation for each property. Nested objects are recursively processed and extracted into separate named interfaces.

Does it handle nested objects and arrays?

Yes. Nested objects produce their own interfaces named after the property key (capitalized). Arrays are typed based on their first element: an array of strings becomes string[], an array of objects generates a separate item interface and becomes ItemName[]. Empty arrays are typed as any[].

Can I convert an array of JSON objects?

Yes. If your JSON root is an array (e.g., [{"id": 1}, {"id": 2}]), the converter uses the first element to infer the item type and generates a RootItem interface along with a type Root = RootItem[] alias.

Is this tool safe for API response data?

Completely safe. The conversion runs entirely in your browser using client-side JavaScript. No data is transmitted to any server. You can safely paste API responses containing tokens, personal data, or any sensitive information.

Related Generate Tools