All tools

JSON to TypeScript

Converters

Paste a JSON response and get TypeScript interfaces, type aliases or a Zod schema — nested types named, optional fields worked out from your samples.

  • Converter
  • JSON
  • Runs offline
  • TypeScript
Output
An array of objects is merged
TypeScript
export interface Order {
  orderId: string;
  placedAt: string;  // ISO 8601 date-time
  customer: Customer;
  items: Item[];
  total: number;
  notes: unknown;
  coupons: unknown[];
}

export interface Item {
  sku: string;
  quantity: number;
  unitPrice: number;
  discountRate?: number;
}

export interface Customer {
  id: number;
  email: string;
}

TypeScript types from a JSON sample

Paste a response from an API and get the types that describe it: one interface per object, nested ones named after their keys, optional fields where a key is missing from some samples, and unions where values differ. Paste an array of objects and they are merged, so one sample fills the gaps of another.

A sample shows what was sent, not everything that can be sent. Treat the result as a first draft and check optional fields, unions and anything typed unknown against the API's documentation.

  • InterfaceThe usual choice for object shapes; can be extended and merged.
  • Type aliasThe same shape as a type; needed for unions and mapped types.
  • Zod schemaValidates data at runtime and infers the type from the schema.
  • unknown, not anyEmpty arrays and always-null fields stay unknown until you know better.

How to use the converter

  1. Paste a JSON sample — or an array of several, to merge them.
  2. Pick the output: Interface, Type or Zod Schema.
  3. Set the Root Name; nested types are named after their keys, in singular for array items.
  4. Read the notes: optional fields, empty arrays and integers too large for JavaScript are called out.
  5. Copy the code or download it as a .ts file.

Examples

Type an API response

A user object with a nested plan, a nullable email and a date.

Merge array items

Two order lines; the discount only one has becomes optional.

Validate it at runtime

The same order as a Zod schema, with dates checked as ISO strings.

Handle awkward keys

Keys with dashes or digits are quoted; a 64-bit ID gets a warning.

Frequently asked questions

Interface or type?

For object shapes either works. Interfaces can be extended and merged, and their errors read a little better; type aliases are needed for unions and mapped types. Pick one and stay consistent.

What is the difference between "?" and "| null"?

email?: string means the key may be missing. email: string | null means the key is always there but may be null. The converter uses ? when a key is missing from some merged samples and | null when a sample had null.

Why does a number have a warning?

JavaScript numbers are exact only up to 2^53. A larger integer — a 64-bit ID, for example — is rounded by JSON.parse. Have the API send it as a string, or parse it as a bigint.

Do these types check data at runtime?

No. TypeScript types disappear when the code is compiled, so a response that does not match them goes unnoticed. Choose Zod Schema to validate data when it arrives.

Is my JSON sent anywhere?

No. The types are generated in your browser; check the Network tab in your developer tools.

Related tools

Learn more