JSON to TypeScript

Paste a JSON sample, such as an API response, to get matching TypeScript interfaces or type aliases, ready to copy into your code.

Your files stay on your device. Nothing is uploaded.

JSON to TypeScript

Updates as you type

Step 1: Paste JSON

Step 2: Choose the style

Write as
Options

Step 3: Copy the types

How to turn JSON into TypeScript types

  1. Paste JSON

    Paste a real example of the data, such as an API response.

  2. Choose the style

    Name the main type, and choose interface or type alias, optional nulls and readonly.

  3. Copy the types

    Copy the types or download a .ts file.

About this tool

Smart about arrays

Items in an array are merged into one type. A key that appears in only some items becomes optional (name?: string), and a value that is sometimes a number and sometimes text becomes a union.

Named nested types

Nested objects get their own named types from their keys, for example users becomes User, and identical shapes share one type instead of repeating.

A starting point

Types come from the sample you paste. If a field can be null or missing in other responses, add that, or tick "Treat null as optional".

Privacy

This tool runs in your browser, on your own device. Your files and text are not uploaded to our server and we cannot see them. When you close or reload this tab, they are cleared, along with the results.

Frequently asked questions

Interface or type alias?

Both work for object shapes. Interfaces can be extended and merged; type aliases can also name unions. Pick what your project uses.

What happens to empty arrays?

They become unknown[], because there is nothing to learn the item type from. Replace it with the real type.

Is my JSON uploaded?

No. It runs in your browser, so nothing you type or choose is sent anywhere.

My JSON has an error

Fix it first with the JSON formatter, which shows the line and column of the problem.