JSON to TypeScript Converter

Paste a JSON sample and get TypeScript interfaces you can copy into your project. The same input always produces the same output. It runs in your browser and nothing is sent anywhere.

Generated types

Paste some JSON to convert.

  • The types describe this sample only. No field is marked optional, so items with different keys become a union.
  • Empty arrays become unknown[] and empty objects become Record<string, unknown>.
  • A null value is typed as null.

How to convert JSON to TypeScript

  1. Paste a JSON object, array or value into the JSON box.
  2. Optionally name the root type. Otherwise it is called Root.
  3. Read any error or assumption shown with the output, then copy the generated types.

Example

This JSON sample:

{
  "id": 42,
  "name": "Ada Lovelace",
  "email": null,
  "tags": [],
  "address": { "city": "London", "post-code": "W1" },
  "orders": [
    { "id": 1, "total": 19.5 },
    { "id": 2, "total": 7, "coupon": "WELCOME" }
  ]
}

generates these types:

export interface Root {
  id: number;
  name: string;
  email: null;
  tags: unknown[];
  address: Address;
  orders: (OrdersItem | OrdersItem2)[];
}

export interface Address {
  city: string;
  "post-code": string;
}

export interface OrdersItem {
  id: number;
  total: number;
}

export interface OrdersItem2 {
  id: number;
  total: number;
  coupon: string;
}

The two orders items have different keys, so each gets its own interface and the array is a union of both. The post-code key is quoted because it is not a valid identifier.

What sample-based inference can and cannot tell you

The converter only knows the JSON you give it. A field that is sometimes missing looks required if it is present in your sample, and a field that is null here is typed as null even if it holds a string elsewhere. Treat the output as a starting point, and paste a sample that includes the variations you care about.

Generated types are also only checked by the compiler. They do not validate data at runtime, so an API response can still differ from them. For runtime checks, a schema library is the better fit: the Zod Type Builder builds validation schemas visually.

Working from a YAML config instead? Convert it with the JSON to YAML converter first, then paste the JSON here.

Frequently asked questions

Why are no fields marked optional?

One sample cannot show that a field is optional, only that it was present this time. When array items have different keys, the converter generates a union of object types, so each item keeps exactly the keys it had. Add ? yourself where you know a field can be missing.

What type does an empty array get?

An empty array becomes unknown[] and an empty object becomes Record<string, unknown>, because the sample says nothing about their contents. Replace them once you know the real shape.

Is my JSON sent anywhere?

No. The conversion runs in your browser. Your input is not uploaded, logged, saved or added to the URL.

How large can the JSON be?

Up to 1,000,000 characters, 64 levels of nesting and 1,000 distinct object shapes. Past a limit you get an error that names it.

How are unusual keys and duplicate type names handled?

Keys that are not valid identifiers are quoted and escaped, such as "post-code". Type names come from the key in PascalCase and are numbered on collision, in input order. Common built-in type names such as Record and Response get a Type suffix. That list does not cover every global, so rename a generated type if it clashes with one you use.