Toolcin

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

Where inference quietly misleads you

SituationWhat you getWhat is actually true
Empty array []never[] or any[]It will hold items later
null in one recordField typed as nullUsually string | null
Mixed numbers and stringsOne of them, silentlyYou need a union, and probably a bug report
DatesstringYes, but only ISO strings if the API is well behaved
Missing key in one recordOptional fieldMay 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

  1. Capture a full response, not a trimmed one. Fields you delete for tidiness become optional in the output.
  2. Convert, then read the result. Two minutes of reading catches most of the misleads above.
  3. Mark what must be required. Remove the ? from fields the API always returns; that is what makes the types useful rather than permissive.
  4. Replace loose types deliberately. Turn string into 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.