Convert JSON to TypeScript types
Paste a representative JSON sample and the converter infers interfaces from the shapes it sees. Then check nullable fields and arrays by hand: an empty array teaches the converter nothing, and a missing key looks optional only if it was missing in your sample.
Hand-writing an interface for a large API response is slow and easy to get wrong: one misspelled field and TypeScript happily accepts code that fails at runtime. A converter reads the real shape and writes the types for you.
What it gets right
- Nesting. Objects inside objects become named interfaces, not one unreadable inline blob.
- Arrays of objects. The element type is inferred from the items present.
- Primitive mapping. Strings, numbers, booleans and nulls map to the obvious TypeScript types.
- Optional-looking keys. A key that appears in some objects but not others becomes optional.
Where inference quietly misleads you
| Situation | What you get | What is actually true |
|---|---|---|
Empty array [] | never[] or any[] | It will hold items later |
null in one record | Field typed as null | Usually string | null |
| Mixed numbers and strings | One of them, silently | You need a union, and probably a bug report |
| Dates | string | Yes, but only ISO strings if the API is well behaved |
| Missing key in one record | Optional field | May be required and simply absent in that sample |
The sample is the ground truth the converter has. A bigger sample is better ground truth: paste five records rather than one, and include a record that has every field.
A workflow that avoids surprises
- Capture a full response, not a trimmed one. Fields you delete for tidiness become optional in the output.
- Convert, then read the result. Two minutes of reading catches most of the misleads above.
- Mark what must be required. Remove the
?from fields the API always returns; that is what makes the types useful rather than permissive. - Replace loose types deliberately. Turn
stringinto a union of known values where the API has an enum, so a typo becomes a compile error.
Do not paste real data
An API response often carries tokens, email addresses and internal identifiers. Converting in the browser keeps it local, but a screenshot of a response with a live token in it is a leak regardless of tooling. Replace the values with placeholders before sharing the output anywhere.
When to stop converting
If the response is enormous — hundreds of fields across dozens of nested objects — a generated file is not a schema, it is a transcript. At that point prefer a validation library such as Zod, define the shape you actually depend on, and let it ignore the rest. Types that describe everything are as hard to maintain as no types at all.
Questions
Does it infer union types?
Only where the sample forces it. Most converters pick the first type they see. If a field can be a string or a number, set that union by hand.
Why did my empty array become never[]?
There was nothing to infer from. Add one example item to the sample, or annotate the array yourself.
Can I convert TypeScript back to JSON?
You can write a sample object that satisfies the interface, but interfaces are erased at runtime — there is nothing stored to convert back.
Is the JSON uploaded?
No. The conversion runs in the browser tab.
Updated 2026-11-16 · written for this site, no trackers, no account.