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.
- Free, no sign-up
- Nothing uploaded
- TypeScript + Zod
or drop a .json file · converted as you type
No JSON handy? Try one:
How it works
- 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.
- Every value is read. Each object gets a type named after its key (
itemsbecomesItem). In a list, a field some items lack becomes optional (discount?: number) and a field that is sometimesnullbecomesstring | null. Objects with the same fields under the same name share one type. - TypeScript and Zod. Interfaces or type aliases, plus Zod validators with
z.infertypes. Whole numbers get.int(); text that is a UUID, date, date-time, e-mail or web address in every value gets the matching check. - Download or copy. One
.tsfile 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| nulland.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?
nullandunknown[], 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.