Skip to content
{//}nullpath

JSON to TypeScript Generator

0 requests sent since load
Input

convert

output

Output

About the JSON to TypeScript generator

Hand-typing interfaces for an API response is slow and error-prone — this tool derives them from a paste of the actual JSON. The root object becomes a namedinterface, nested objects become their own interfaces — recursively, at any depth — and arrays become typed element arrays. Paste one representative response and you get a compilable starting point in seconds, entirely in your browser.

Structural inference

Across the objects in an array, keys are merged into a single interface. A key present in every instance is required; a key missing from at least one instance — a sparse row — is marked optional with?. If the same key holds different types in different rows, you get a union like string | number. Heterogeneous arrays (e.g. ["a", 1, true]) produce an element-level union, and empty arrays infer as unknown[].

Limitations

The output reflects the shape(s) you provide — it cannot invent constraints for data you didn't paste, and optionality is judged only within each array, not between them. Machine precision and literal-type narrowing are out of scope; this tool is about getting the shape right so you can refine from there. Pair it with JSON Schema if you need to validate rather than type.

Related tools

Generate validation instead of types with the JSON Schema generator, or tidy the source document first with the JSON formatter.

FAQ

Why use `unknown[]` for empty arrays?

An empty array carries no type information, so assigning any would hide errors. unknown[] forces you to narrow before use.

Does output need the `interface` exported?

Interfaces are emitted without export; add it where you need cross-file usage.