JSON to TypeScript

Turn a sample API response or config into TypeScript types you can paste into your project. Nested objects get their own named types.

Runs in your browser. Nothing is uploaded Free, no sign-up Works on mobile
Root type name
Declare as
Null fields

Types are guessed from this one sample. Paste a list with several records to catch optional keys, and check fields that are null here but hold another type in real data.

How to convert JSON to TypeScript

  1. Paste JSON or open a .json file.
  2. Set the root name and choose interface or type.
  3. Copy the types or save them as types.ts.

Features

  • Interfaces or type aliases
  • Named types for nested objects
  • Optional keys from merged arrays
  • Union types and null handling
  • export and readonly options
  • Optional Zod schema output

Frequently asked questions

How are arrays of different objects handled?

Every object in a list is merged into one type. A key that appears in only some of the objects is marked optional with ?, and a key with different value types becomes a union such as string | number.

What happens to null values?

By default a null field is typed as its other types plus null, for example string | null. Choose “x?: T | null” to also make such fields optional. A field that is only ever null is typed as null.

What is the Zod schema for?

Zod checks data at runtime, for example an API response, and throws if it does not match. Tick “Also make a Zod schema” to get z.object() schemas that match the types.

Why is an empty array typed as unknown[]?

An empty list gives no clue about what it holds. Add one sample item to the JSON, or edit unknown[] to the right type after copying.

Is my data sent to a server?

No. Everything runs in your browser, so configs, API responses and code never leave your device.

Related tools

All Developer Tools →