JSON to TypeScript
Generate TypeScript interfaces from a JSON sample. Infers nested objects, arrays, unions, and optional keys — entirely in your browser.
About this tool
Paste a representative JSON response and get back TypeScript interfaces
that describe it. The converter walks the value recursively: objects
become interfaces, arrays become element-typed arrays, and primitives are
widened to string, number, or
boolean. Nested objects are extracted into their own named
interfaces so the output stays readable rather than deeply inlined.
The interesting work happens with arrays of objects.
Real API data is rarely uniform — some records carry a field others omit.
Rather than emit one interface per element, the tool merges every object
in an array into a single shape: keys that appear everywhere are required,
keys that appear only sometimes become optional?, and a key
with mixed types becomes a union. Feed it a handful of real records and the
resulting interface captures the true contract, not just the first row.
Everything is inference from a sample, so treat the output as a strong
starting point, not gospel: it widens primitives (no literal-union or
enum inference), models JSON null as the null
type, and names interfaces from their keys. Adjust names, tighten unions,
and add enums by hand where your real schema is stricter than any single
sample reveals. Because it runs client-side, you can paste production
payloads with PII without anything leaving your machine.
Frequently asked questions
How does it handle an array of objects with different keys?
It merges them into one interface. A key present in every element is required; a key missing from some elements becomes optional (key?). The property type is the union of the types seen for that key across all elements.
What happens with null values?
A null becomes the literal type null. If a key is sometimes null and sometimes a string, you get string | null. Because JSON has no undefined, missing keys are modelled as optional rather than as undefined.
Does it generate interfaces or types?
Interfaces, one per distinct object shape, named after the key that holds them (arrays are singularized — projects becomes a Project interface). Toggle the export option to prefix each with export. A non-object top level (array or primitive) is emitted as a type alias.
Will it infer literal or enum types?
No — it widens primitives to string, number, and boolean rather than inferring literal unions like 'admin' | 'user'. Widening is what you want for most API payloads; tighten by hand where you need an enum.
Is my JSON uploaded anywhere?
No. Parsing and type inference run entirely in your browser. The JSON you paste never leaves your device.