JSON to TypeScript

Generate Interfaces from JSON.

Loading…

You have an API response and you need types for it. Writing interfaces by hand for forty fields is slow, and it's easy to mistype one. Paste the JSON and the interfaces are written for you.

Nested objects become their own named interfaces. Arrays are typed by their contents, including mixed ones. When objects in an array don't all have the same keys, the missing ones are marked optional.

How to use the JSON to TypeScript tool

  1. Paste a JSON sample.
  2. Name the main type and choose interface or type.
  3. Copy the TypeScript into your project.
  • Typing a third-party API response
  • Adding types to a JavaScript project during migration
  • Quick models for a prototype or a test

Tips for the best result

  • Use a sample with several array items, so optional and nullable fields are detected.
  • A null value gives the type null. Widen it by hand if you know what it can hold.

Quick facts

PriceFree
Works withJSON → TS
Where it runsIn your browser, on your device
AccountNot needed

Frequently asked questions

Does it detect dates or enums?

No. A date string is typed as string, and repeated values are not turned into unions.

What happens with an empty array?

It is typed as unknown[], since there is nothing to infer from.

Interface or type: which should I choose?

Both work for object shapes. Interfaces are the common convention for API models.

Is the JSON uploaded?

No. Your sample stays on your device.