Skip to content

JSON to TypeScript

Paste a JSON sample and get ready-made TypeScript types for it.

  • Free, no account
  • Nothing uploaded
  • 13 tools
Input
Output
working…in 338 B · 11 linesProcessed in this tab, no request made

Nothing you paste is uploaded. The server sends connect-src 'self', so your browser blocks this page from contacting any other host. Check it yourself

Generate TypeScript interfaces from a JSON sample: nested objects get their own names, arrays are typed from every item and missing keys become optional.

From a JSON sample to interfaces

Each nested object becomes its own named interface, named after the key that holds it. Arrays are typed from all their items, which is where most generators that look only at the first item go wrong:

{ "items": [ { "sku": "A", "qty": 2 }, { "sku": "B", "qty": 1, "backorder": true } ] }

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

export interface Root {
  items: Item[];
}

backorder is optional because one item lacks it. A key whose values have different types becomes a union. The name of the root interface is yours to set in the toolbar.

Limits of inferring types from one sample

The output describes the sample you gave, not the API. A field that happens to be null in the sample is typed null; an empty array is typed unknown[]; a string that is always one of three values is still string. Treat the result as a first draft and tighten it against the API's documentation.

If the sample does not parse, check it in the JSON validator first.

Questions

Short answers to what people ask most.

How are arrays typed?

From every item, not just the first. Items that are objects are merged into one interface; a key that is absent in some items becomes optional, and a key whose value differs in type becomes a union such as number | string.

Why is a property typed as null?

Because every sample value for that key was null, so the sample gives no other information. Replace it by hand with the real type, for example string | null.

Does it produce Zod schemas or type guards?

No, only interfaces and type aliases. The output describes the sample; it does not validate data at run time.

What happens with keys that are not valid identifiers?

They are written in quotes, for example "first-name": string, which is valid TypeScript and matches the JSON exactly.