JSON to TypeScript Interface

Generate TypeScript interfaces from a JSON sample, including nested objects and arrays.

How do you create TypeScript types from JSON?

A JSON to TypeScript generator inspects a JSON sample and writes matching TypeScript interfaces, giving every property a type, so API responses can be used safely with autocompletion.

How types are inferred

  • Strings, numbers and booleans map to string, number and boolean; null maps to null.
  • Nested objects get their own named interface (e.g. address → Address).
  • Arrays are typed from their items; arrays of objects get an item interface with a singular name.
  • Keys that appear in only some array items are marked optional (?).
  • Keys that are not valid identifiers are quoted.

Tips

Use a realistic sample with every field filled in at least once, so optional and nullable fields are detected. Review the result and refine union types (for example string literals) by hand where your API documents them.

Frequently asked questions

Interface or type alias?

Interfaces are generated because they are easy to extend; a type alias is used only when the root JSON is not an object.

Why is a field typed as unknown[]?

The sample array was empty, so the item type could not be inferred.

Is the JSON sent to a server?

No, generation happens in your browser.