JSON to TypeScript Interfaces

Paste an API response, get typed interfaces.

Paste a JSON sample, typically an API response, and get TypeScript interfaces that describe it. Each nested object becomes its own named interface, arrays are typed from their elements, and the root type is exported as Root.

When an array contains objects with different keys, the shapes are merged: a field that is missing from some elements is marked optional, and a field that holds more than one type becomes a union.

How to use it

  1. Paste a representative JSON sample into the left editor.
  2. Review the generated interfaces on the right.
  3. Copy them into your project and rename Root to suit your model.

Questions

How are optional fields detected?

Only by comparing the objects inside an array. A key missing from at least one element is marked optional. A single sample object cannot reveal which fields are optional.

How is null typed?

A null value is typed as null and combined into a union when other samples of the same field have a value, for example string | null.

Does it work from YAML or XML?

Yes. Any supported input format is parsed first, so you can generate types from YAML, XML, CSV, JSONL or TOON as well.

All tools