JSON to Zod Schema
Paste a JSON sample and get a Zod schema for it, written as code you can paste into a TypeScript project. Fields that are missing from some samples become optional, and the inferred type is added.
- Free, no sign-up
- Nothing is sent to a server
- Worldwide
How to use JSON to Zod Schema online
- Paste a JSON sample. A list of objects gives the richest result.
- Name the type. It sets the schema and type names.
- Choose the options. Optional fields, formats, strict or loose.
- Copy the code. Paste it into your project.
Why use this free JSON to Zod Schema
- Objects, lists and unions
- Optional fields from several samples
- Nullable fields
- Email, URL, UUID and date checks
- Strict, strip or passthrough
- The z.infer type
What the generator reads
Zod is a TypeScript library that checks data at run time. Writing a schema by hand for a large API answer is slow, so this page reads a sample and writes the schema. Objects become z.object, lists become z.array, and text, numbers, true or false and null each get their own call. A list of objects is merged, so the schema covers every object in it.
Optional and nullable fields
When a list holds several objects and a key is missing from some of them, that field is marked optional. When a value is null in one object and text in another, the field becomes nullable. A single object cannot show which fields may be missing, so the page cannot know. Give it several samples in a list when you can.
Formats and whole numbers
Text that looks like an email, a web address, a UUID, a date or a date and time can get the matching Zod check. Whole numbers can be written with the int check. These are guesses from the sample, so a value that happens to look like an email is not always one. Turn the options off if you want plain strings.
Unknown keys
Zod removes keys that are not in the schema by default. You can choose strict, which rejects them, or passthrough, which keeps them. Pick the one that matches how your program should treat data it does not know.
Limits
The schema describes the sample and nothing more. Ranges, lengths, patterns and rules between fields have to be added by hand. A schema built from one sample can be too narrow, so test it with real data before you trust it. Nothing is uploaded; the JSON is read in your browser.
Using the tool
Change the text or any option of the JSON to Zod Schema and the answer moves straight away. Find and replace is built into the editor with Ctrl+F and Ctrl+H.
JSON to Zod Schema: frequently asked questions
Which Zod version does the output fit?
Why is one of my fields not optional?
Can it handle nested lists?
What happens to a field that is sometimes a number and sometimes text?
Does it need valid JSON?
Is the text I paste into the JSON to Zod Schema uploaded?
Can I copy the JSON to Zod Schema result?
Related searches for JSON to Zod Schema
- JSON to Zod Schema online
- free JSON to Zod Schema
- JSON to Zod Schema online free
- JSON to Zod Schema for mobile
- JSON to Zod Schema without sign up
- convert json to zod schema
- json to zod schema converter
- JSON to Zod Schema – Developer & Web Tools
JSON to Zod Schema is a free online tool on MAITBOX, in the Developer & Web Tools group. It runs in your browser, so what you type is not sent to a server. It works on Android and iPhone, and on Windows, Mac and Linux, with no download and no account.