Tools JSON

JSON to TypeScript

Generate TypeScript interfaces from a JSON sample.

🔒 Runs in your browser. Nothing is uploaded.
TypeScript

How to use it

  1. Paste a JSON sample, such as an API response.
  2. Read the generated interfaces on the right. They update as you type.
  3. Change the root type name if you want something more specific than Root.
  4. Copy the result or download it as a .ts file.

Questions

How are arrays of objects handled?

Every item is merged into one interface. A key that is missing from some items becomes optional (key?:), and a key whose values have different types gets a union, such as number | null.

How are nested types named?

After their key in PascalCase. Array items get a singular name, so "users" becomes User and "categories" becomes Category; other arrays get an Item suffix. If two types would share a name, the second gets a number.

Why is a field typed as unknown[]?

The array was empty in your sample, so there was nothing to infer the item type from. Paste a sample with at least one item, or edit the type by hand.

Is my JSON uploaded?

No. The types are generated in your browser, and the page’s security policy blocks it from sending your data anywhere.