JSON to TypeScript Interface Generator

Paste an API response and get ready-to-use TypeScript interfaces. Every item in an array is inspected, so optional fields and mixed types are typed correctly.

TypeScript
Ctrl + Enter to run

Runs 100% in your browser — your data is never uploaded to our server.

Typed models from real data

Writing interfaces by hand for a large API response is slow and error-prone. This generator reads your JSON and produces TypeScript declarations that match it. Unlike simple converters that only look at the first element of an array, it merges every element: if a property exists in some objects but not others it becomes optional (archived?: boolean), and if a property holds different kinds of values it becomes a union (string | null).

Nested objects get their own named interfaces (derived from the property name, e.g. profile → Profile, projects → Project), and identical shapes are reused instead of being duplicated.

How to use it

  1. Paste a representative JSON sample — the more array items it contains, the more accurate the optional fields will be.
  2. Set the root type name, choose interface or type, and toggle export / readonly.
  3. Copy the result into a .ts file or download it.

Example

JSON

{
  "id": 1,
  "tags": ["a"],
  "items": [
    {"sku": "A", "qty": 1},
    {"sku": "B", "qty": 2, "note": "gift"}
  ]
}

TypeScript

export interface Root {
  id: number;
  tags: string[];
  items: Item[];
}

export interface Item {
  sku: string;
  qty: number;
  note?: string;
}

Type mapping

JSON valueTypeScript type
"text"string
42, 3.14number
trueboolean
nullnull (combined into a union when other values exist)
[] (empty)unknown[]
objecta named interface

Dates arrive in JSON as strings, so they are typed as string. Convert them to Date in your code if needed.

Frequently asked questions

Should I use interface or type?

Both describe object shapes. Interfaces can be extended and merged, which many teams prefer for API models; type aliases are needed for unions. Pick whichever matches your codebase style.

Why is a field typed as null?

Your sample only contained null for that field. Add a sample where it has a real value and the type becomes a union such as string | null.

Does it support property names with spaces or dashes?

Yes. Such keys are written in quotes, e.g. "first-name": string.

Is my JSON uploaded?

No. Generation happens in your browser.