Skip to content
Devtoolry

JSON to TypeScript

Generate TypeScript interfaces from JSON online, including nested objects and arrays. Paste an API response and copy ready-to-use types into your code.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the JSON to TypeScript

The JSON to TypeScript converter generates interfaces (or type aliases) from a sample response, including nested objects and arrays, so you can type API data without writing it by hand.

Conversion happens in your browser, so your files and records stay private.

How to use the JSON to TypeScript

  1. Paste a representative JSON sample.
  2. Set the root type name and choose interface or type.
  3. Copy the generated types into your project.

Example

Generate interfaces from a user object

Input

{
  "id": 42,
  "name": "Ada",
  "tags": ["admin"],
  "address": { "city": "London", "zip": null },
  "orders": [
    { "id": 1, "total": 9.5 },
    { "id": 2, "total": 12, "coupon": "SAVE10" }
  ]
}

Result

export interface User {
  id: number;
  name: string;
  tags: string[];
  address: Address;
  orders: Order[];
}

export interface Order {
  id: number;
  total: number;
  coupon?: string;
}

export interface Address {
  city: string;
  zip: null;
}

Root type name set to "User". "coupon" is optional because only one order has it, and the nested types are named after their keys.

Common mistakes

  • null in the sample. A field that is null in your sample becomes the type null. If it can also hold a value, change it by hand, for example zip: string | null.
  • One item is not enough. Optional fields are found by comparing items in an array. Paste an array with several representative records, including ones with missing fields.
  • Empty arrays. An empty array gives no information about its items. Add at least one element to the sample so the item type can be inferred.
  • Types are not validation. Interfaces disappear at runtime. If the API might return something else, validate responses with a schema library such as Zod.

Works well with the JSON to TypeScript

Frequently asked questions

How are optional fields detected?

When an array contains objects with different keys, keys missing from some items are marked optional.

Should I trust generated types?

They describe the sample you pasted. Check them against your API documentation, especially for nullable fields.

interface or type alias?

Both describe object shapes. Interfaces can be extended and merged, which suits API models; type aliases are needed for unions. Pick the option your codebase uses.

How are nested objects named?

Each nested object gets its own interface named after its key in PascalCase, such as address → Address, and array items use the singular, such as orders → Order.

Guides and tutorials