JSON to TypeScript
Generate interfaces from a sample — every array element, not just the first.
What you paste
Parsed in your browser — never uploadedHow this reads your output
The sample is walked and every array element is inspected rather than only the first. That is the difference that matters: a real API response has rows where one field is missing and another is null, and types generated from the first element compile against your sample and fail against the second row of the same response. Here a key missing from any element becomes optional, a key that is a string in one and null in another becomes a union, and a key whose shape changes entirely becomes unknown — which forces you to look at it rather than accept a confident guess.
What the results mean
- Optional fields
- Keys missing from at least one element of an array. Marked with a question mark, which is what stops runtime errors on the rows that lack them.
- Unresolved fields
- Keys whose type changed shape between elements. Typed as unknown deliberately — these are the ones worth checking against the API documentation.
- Interfaces
- One per distinct object shape, named from the key that contained it, with the root first.
- Array elements sampled
- How many rows contributed to the types. More rows, and rows with variation, produce types that match the real API.
Common problems and fixes
- Everything came out required but the API says optional
- Your sample has no rows missing those fields. Paste a response with more variety — including error and empty cases — and the optionality will follow.
- A date came out as string
- Correct, in the sense that JSON has no date type. Narrow it yourself once you know the format is guaranteed.
- The interface names are awkward
- They are derived from the key that held each object. Rename them once generated — the structure is the part worth automating.
Frequently asked questions
Why do types from a single array element go wrong?
Because real collections are not uniform. One row omits a nullable field, another has null where the rest have a string, a third carries an extra flag. Types built from element zero declare all of that as required and present, so the code compiles, ships, and throws on row two. Reading every element and unioning what is found is slower and produces types that survive the real response.
Does this handle nested objects and arrays?
Yes. Nested objects become their own interfaces named after the key that held them, and arrays are typed by the union of everything inside them, at any depth.
Is my JSON uploaded?
No. The conversion happens in your browser — worth knowing when the sample is a real API response with real customer data in it.
Put this on your own site
Free to embed, no attribution required beyond the source link the frame carries itself. It runs entirely in your visitor's browser, sets no cookies and loads no third-party script.
<iframe src="https://runthetests.com/embed/json-to-typescript/" width="100%" height="720" style="border:1px solid #e5e5e5;border-radius:8px" title="JSON to TypeScript" loading="lazy"></iframe>
Preview it at https://runthetests.com/embed/json-to-typescript/. Embedded pages are marked noindex, so yours stays the canonical copy — not this one.