JSON to TypeScript Interface
Paste a sample JSON and generate inferred TypeScript interfaces: nested objects become their own interfaces, arrays become T[] and heterogeneous items become a union. The root interface name is configurable.
Paste a sample JSON and generate inferred TypeScript interfaces: nested objects become their own interfaces, arrays become T[] and heterogeneous items become a union. The root interface name is configurable.
The tool runs JSON.parse on the text and walks the structure inferring the
basic types (string, number, boolean, null).
Each nested object becomes a separate interface, named
from the key (in PascalCase). Objects with the same shape are reused
in a single interface. Arrays become T[]; when items have
different types, the element becomes a union, for example
(number | string)[].
The goal is to be simple and predictable: basic types, nested objects and
arrays. Optional fields are not inferred (all come out as required), and
an empty array becomes unknown[], since there is no item to inspect. Keys that
are not valid identifiers (with a hyphen, for example) come out quoted, as TypeScript
requires.
The tool shows a readable error message (the same one from
JSON.parse) and doesn't generate output, without breaking the page. Fix the JSON and
generation happens live as you type.
When two objects have exactly the same keys and types, they share a single interface — reducing duplication. If you need distinct names, rename them in the generated code.