Menu
PDF Tools
Image Tools
Converters & Utilities
Seller & Print Tools
Accounting & Business
Calculators
Text & Writing Tools
Developer & Web Tools
Creator & Social Tools
Browser Utilities & Games
Document & Design Makers
Text & Developer Tools
Exam & Form Tools

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.

How to use JSON to Zod Schema online

  1. Paste a JSON sample. A list of objects gives the richest result.
  2. Name the type. It sets the schema and type names.
  3. Choose the options. Optional fields, formats, strict or loose.
  4. 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?
It uses calls that exist in current Zod releases, such as z.object, z.array, z.string().email() and z.infer. Check the Zod notes for your version if a call is missing.
Why is one of my fields not optional?
Only a key that is absent from at least one object in a list is marked optional. A single object gives no sign of that.
Can it handle nested lists?
Yes. Lists inside lists and objects inside lists are followed to any depth.
What happens to a field that is sometimes a number and sometimes text?
It becomes a union of the kinds that were seen.
Does it need valid JSON?
Yes. If the text is broken, use the JSON Repair tool first and paste the result here.
Is the text I paste into the JSON to Zod Schema uploaded?
The JSON to Zod Schema works locally, and clearing the site data removes anything the editor saved.
Can I copy the JSON to Zod Schema result?
Save the JSON to Zod Schema result as a text file, or copy it from the result box.

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.

More tools in Developer & Web Tools →

Search tools