JSON to TypeScript Converter

Generate TypeScript interfaces from a sample JSON response.

Result

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

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

export interface Order {
  id: number;
  total: number;
  coupon?: string;
}
19 lines · 267 bytes
  • Types come from the sample you paste. A key missing from some array items becomes optional (?), and mixed values become a union. A single sample cannot know every case, so review before use.

How do you turn JSON into TypeScript types?

TypeScript checks the shape of your data while you code. When you receive JSON from an API, you need a type that describes it. Writing that by hand for a large response is slow and easy to get wrong.

This tool reads a sample and infers the types. Nested objects get their own named interfaces, arrays become typed arrays, a key missing from some items becomes optional, and mixed values become a union. The sample produces User, Address and Order, with coupon marked optional on Order.

How to use the JSON to TypeScript Converter

  1. Paste a sample JSON object or array.
  2. Name the root type, for example User.
  3. Choose interface or type, and whether to export.
  4. Copy the generated TypeScript.

Real situations

When people use the JSON to TypeScript Converter

  • 1

    Type an API response quickly

    Paste a real response, name the root type and get interfaces to drop into your project.

  • 2

    Start from a sample and refine

    Use the output as a first draft, then tighten a few fields, such as turning a string into a union of known values.

  • 3

    Document a payload

    Share an interface instead of a long JSON example in a pull request or an issue.

  • 4

    Learn the shape of unknown data

    See at a glance which fields are arrays, which are nested objects and which are sometimes missing.

Good to know

  • The more varied your sample, the better the result. Include items that have optional fields.
  • A null in the sample is typed as null only, so widen it by hand if the real value can be a string.

FAQ

JSON to TypeScript Converter: questions answered

How do I generate TypeScript from JSON?

Paste a sample response, set the root name and pick interface or type. For the sample, the tool outputs export interface User with id, name, email, roles, address and orders, plus Address and Order interfaces.

How are optional properties found?

If a key is missing from some items in an array, it is marked with a question mark. In the sample, coupon appears in one order and not the other, so Order gets coupon?: string.

Why is email typed as null?

The sample has "email": null, and one sample cannot show what else it may hold. The tool types it as null, so you should change it to string | null if that is what the real API returns.

Interface or type, which should I use?

Both describe object shapes. Interfaces can be extended and merged, and type aliases can also name unions. The tool lets you choose, and the output is otherwise the same.

Can it handle mixed arrays?

Yes. If an array holds different kinds of values, the type becomes a union. Review it, since a single sample may not show every case.

Is the generated code safe to use as is?

Treat it as a draft. It reflects only the sample you pasted. A real API can return other shapes, so review before relying on it.

Is this JSON to TypeScript Converter free and private?

Yes. It is free with no sign-in, and every calculation runs inside your browser. Nothing you type is sent to a server or stored, and the page keeps working offline once it has loaded.

Private by design. No accounts, no cookies, no tracking. Everything you type stays on your device.

How we keep it that way