Free JSON to Zod Schema Generator

Convert JSON to a Zod schema online. Detects integers, optional and nullable fields, emails, URLs, UUIDs and dates, and exports z.infer types for TypeScript.

  • No upload, 100% private
  • Instant, in your browser
  • 100% free, no signup
Loading tool…
Read the complete guideHow to Validate API Responses in TypeScript With Zod Schemas →

About the JSON to Zod Schema tool

TypeScript types disappear at runtime, so they cannot stop a bad API response from breaking your app. Zod fills that gap: a schema validates data as it arrives and gives you the matching TypeScript type through z.infer. Writing the schema for a large payload by hand is slow, though, and this JSON to Zod generator does it from a sample.

Every object becomes a z.object with its own named schema, arrays become z.array, and whole numbers are marked with .int(). Keys missing from some array items get .optional(), null values get .nullable(), and keys with mixed types become z.union. With format detection on, strings that are all emails, URLs, UUIDs, ISO dates or date-times get the matching Zod refinement such as .email() or .datetime(). You can add .strict() to reject unknown keys and export z.infer types alongside the schemas.

Schemas are declared in dependency order so the file works as soon as you paste it. The generator runs in your browser and never sends your data anywhere.

How to use JSON to Zod Schema

  1. Paste JSON into “JSON sample”, open a file, or click “Load sample”.
  2. Set the “Root type name”; the main schema is called RootNameSchema.
  3. Toggle “Detect email, URL, UUID & dates”, “.strict() objects” and “Export z.infer types”.
  4. Review the schema in the output pane.
  5. Copy it or download it as a .ts file.

Features

Complete Zod schemas

Objects, arrays, integers, booleans, optional, nullable and union types.

String format detection

Adds .email(), .url(), .uuid(), .date() or .datetime() when every sample value matches.

z.infer types

Exports a TypeScript type for each schema so you don't maintain types twice.

Strict mode option

Adds .strict() so unexpected keys fail validation.

Dependency-ordered output

Nested schemas are defined before they are referenced.

When to use it

  • Validate responses from a third-party API in a Next.js or Remix app.
  • Create a schema for a form submission handled by a server action.
  • Check environment or JSON config files at startup.
  • Guard tRPC or Express endpoints with input validation.
  • Turn example webhook payloads into validated, typed handlers.

Frequently asked questions

Which Zod version is the output for?

Zod 3. The same syntax works in Zod 4 for objects and primitives, although Zod 4 also offers top-level helpers such as z.email().

Why is a field z.null()?

The sample only contained null for that key. Replace it with the real type followed by .nullable().

When is .int() added?

When every sample value for that key is a whole number. One decimal value makes it a plain z.number().

Can the detected formats be wrong?

They are guesses from your sample. If a value might not always be a valid email or URL, remove the refinement.

Is my JSON uploaded?

No. The schema is generated locally in your browser.

Related tools