JSON to TypeScript

Paste a sample of your JSON and get TypeScript interfaces for it. Nested objects get their own named interface, and keys missing from some items are optional.

How it works

Each object becomes an interface named after its key: address becomes Address, and the items of users become User. The top type is called Root unless you give it another name.

Every item of an array is merged. A key missing from some items is marked optional with ?, and values of different types become a union such as string | null.

Two objects with the same shape share one interface. Two different shapes that want the same name get Item and Item2. Every number is typed number, big ones included, because that is what JSON.parse gives your code.

How to use it

  1. 1 Paste a JSON sample, such as an API response.
  2. 2 Name the top type, for example Order or ApiResponse.
  3. 3 Read the interfaces and rename any that read badly.
  4. 4 Press Copy result or Download .ts and paste it into your project.

Good to know

  • Paste several records in an array, not one. That is how the tool learns which keys are optional.
  • Include a record where a value is null, so its type gets | null.
  • An empty array becomes unknown[], because there is nothing to infer from. Replace it with the real type.
  • Keys that are not valid identifiers, such as "first name" or "x-id", are written in quotes.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Typing an API response without writing it by hand

When a TypeScript project reads JSON from an API, the compiler knows nothing about its shape. The value is any, or unknown, and every property access is a guess. Writing interfaces for the response fixes that, but a real payload can have dozens of keys and several nested objects. Typing them by hand is slow, and it is easy to miss a key or get a type wrong. Generating them from a real sample gives you a correct first draft in a second.

This tool walks your sample and writes one interface per object. Names come from the keys: the object under address becomes Address, and the items of a users array become User, because a list of users holds users. Arrays of plain values become string[] or number[]. A list that mixes types becomes a union, such as (string | number)[]. When two objects have exactly the same keys and types, they share one interface instead of producing two copies. When two different shapes would get the same name, the second becomes Item2, so nothing is silently merged.

The most useful part is how arrays of records are read. Real data is not uniform. One order has a coupon and the next does not. One user has an email and another has null. The tool merges every item of an array, so a key missing from any item is marked optional with ?, and a key that is sometimes null gets | null. The more records you paste, the closer the types come to what the API really returns. With one record, everything looks required.

Numbers deserve a note. JSON has one number type, and JSON.parse turns every one into a JavaScript number. So the tool types them all as number, including integers too large for a number to hold exactly. That is honest: it is what your code receives. If the API sends 19-digit IDs, they are already rounded by the time your code sees them, and the fix is for the API to send them as strings.

Treat the result as a draft. Rename interfaces whose names read badly, replace unknown[] for arrays that were empty in the sample, and tighten string to a union of literal values where you know the options. Everything is generated in your browser, so you can paste a production response with real customer data and nothing is sent anywhere.

Frequently asked questions

Why is a key marked optional?

Because at least one item in the same array did not have it. If the key is always present in your real data, remove the ? by hand or paste a sample where every item has it.

Why is a 19-digit ID typed number and not bigint or string?

JSON.parse returns every JSON number as a JavaScript number, so number is what your code actually receives, rounded digits and all. If you need the exact digits, the API should send the ID as a string.

Does it write type aliases or interfaces?

Interfaces for objects. When the top value is an array or a plain value, it writes a type alias, such as export type Root = RootItem[].

Is my JSON sent to a server?

No. The types are built in this page, from up to 2 MB of JSON at a time.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.