JSON to TypeScript Interfaces

How it works
Indent
Valid JSON

Input JSON

No problems found. This is valid JSON.

About JSON to TypeScript

Typing an API response by hand is slow and easy to get wrong. Paste an example response and this tool writes the TypeScript interfaces for it: a Root interface for the top level, plus one interface per nested object, named after its key.

Arrays of objects are merged into a single interface, so a key that only some items have becomes optional with ?. Mixed values become unions such as string | number, and empty arrays are typed unknown[] until you know more.

How to use it

  1. Paste a sample of your JSON into the Input panel.
  2. Choose Convert to TypeScript as the Output.
  3. Review the generated interfaces and rename any that need a better name.
  4. Copy them into your project or download a .ts file.

Frequently asked questions

How are the interfaces named?

From their keys in PascalCase: a "user" object becomes User, and the items of a "categories" array become Category. Duplicate names get a number, such as Meta2.

Why is a property typed null?

The sample only had null for that key, so its real type can’t be known. Replace null with the right type, for example string | null.

What about keys with spaces or dashes?

They are kept and quoted, for example "first name": string, so the interface still matches the JSON exactly.

Related tools