JSON to TypeScript
← SkillSafe

Turn JSON into TypeScript types

Paste or drop JSON and get TypeScript interfaces plus matching Zod validators, with optional and nullable fields read from every value.

or drop a .json file · converted as you type
No JSON handy? Try one:

How it works

  1. Paste or drop the JSON. An API response, a config file, a list of records or a JSON Lines log. Comments and trailing commas are removed first; anything else that is not JSON gets the line and column where it breaks.
  2. Every value is read. Each object gets a type named after its key (items becomes Item). In a list, a field some items lack becomes optional (discount?: number) and a field that is sometimes null becomes string | null. Objects with the same fields under the same name share one type.
  3. TypeScript and Zod. Interfaces or type aliases, plus Zod validators with z.infer types. Whole numbers get .int(); text that is a UUID, date, date-time, e-mail or web address in every value gets the matching check.
  4. Download or copy. One .ts file of types and one of Zod validators, ready to drop into your project.

Questions

Is my JSON uploaded?
No. The JSON is read inside your browser tab and the TypeScript is written there too. Only the optional AI step sends anything: the generated types and a summary of each field (its name, type and counts and, if you leave the box ticked, up to five example values), and only when you press its button.
How does it decide that a field is optional?
In a list of objects, a field that some items have and others lack gets a question mark (field?: type) and .optional() in Zod. A field that is present but sometimes null gets | null and .nullable(). The page counts every item, so paste a sample that shows the variety your API really returns.
Which Zod version does it write for?
It uses only methods that exist in both Zod 3 and Zod 4: z.object, z.array, z.union, z.enum, .optional(), .nullable(), .int(), and the string checks .uuid(), .email(), .url(), .date() and .datetime({ offset: true }).
Can it read JSON Lines or JSON with comments?
Yes. A file with one JSON object per line is read as a list. Comments and trailing commas are removed before reading, and the page says so. Anything else that is not JSON gets the line and column where it stops being valid.
A field is always null or a list is always empty. What type does it get?
null and unknown[], because the JSON does not show anything else. The page lists these fields so you can set the real type by hand, or paste a sample where they have values.
How big a file can it take?
Up to 20 MB. For very large files the first 200,000 values are read to learn the types.