Skip to content
Esc

JSON to TypeScript

TypeScript interfaces from a JSON sample.

Try

About this tool

Runs in
your browser
Your input sent to our servers
Nothing
Kept on this device
nothing

More in the privacy policy.

How to use it

  1. 01Paste a JSON sample, such as an API response, open a .json file or drop one on the page. Or pick one under Try.
  2. 02The TypeScript types appear as you type: one interface for the root and one for each nested object. Change the root name, choose interface or type, and whether to export them.
  3. 03Copy the types or download them as a .ts file.

Related tools

Questions

How does it decide which fields are optional?

From arrays of objects: every item is merged into one interface, and a field missing from some items gets a question mark. [{"id": 1, "email": "a@example.com"}, {"id": 2}] gives type RootObject = RootObjectItem[]; interface RootObjectItem { id: number; email?: string; }

Why is a field typed null?

The sample only had null there, so it can’t tell what the field holds otherwise. Replace null with the real type, for example string | null.

Are the types exact?

They describe the sample you paste, not every response the API can send. A field that is sometimes missing or of another type only shows up if the sample has it; check the API’s documentation for the full picture, and paste several items in an array to cover more cases.

How are the names chosen?

From the keys, in PascalCase, with array items in the singular: "users" gives User, "categories" Category. A name TypeScript already uses gets Type added (DateType for "date"), and a key used twice in different places gets a number.

Is my JSON sent anywhere?

No. The types are worked out in your browser, and a file you open is read there too. It isn’t sent to our servers, put into the page address or saved.