JSON Schema to Zod screenshot

JSON Schema to Zod

Turn a JSON Schema into a Zod schema: required properties plain, optional ones `.optional()`, nested objects inline.

Privacy First
0 Runs
Updated 2026-11-17
Runs in your browser
No sign-up, no upload

What the JSON Schema to Zod does

Each JSON Schema type maps to one Zod constructor: string, number, integer (z.number().int()), boolean, null, array and object. An enum becomes z.enum([...]) with the schema's own values.

Nested objects are written inline, indented by depth, because Zod composes by nesting. A nested object with a title still becomes an inline object: a named export would be a second declaration you did not ask for.

$ref, oneOf, anyOf, allOf, not, if and patternProperties are refused by name. Constraints beyond type and requiredness — minLength, pattern, format — are not emitted, so the validator is looser than the schema.

How to use it

Paste the schema into the JSON Schema box, or press Run with the example already there.

Read the Zod schema below: the root is one exported z.object, with nested objects indented inside it.

Check an optional property in the Zod schema — it carries .optional(), and a required one does not.

Worked example

Input:

{
  "title": "User",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        }
      },
      "required": [
        "city"
      ]
    }
  },
  "required": [
    "id"
  ]
}

Output:

import { z } from "zod";

export const User = z.object({
  id: z.number().int(),
  name: z.string().optional(),
  tags: z.array(z.string()).optional(),
  address: z.object({
    city: z.string(),
  }).optional(),
});

Why it runs in your browser

The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.

A Zod validator that mirrors the schema: `z.number().int()` for an integer, `z.array()` for an array, and `.optional()` on exactly the properties the schema leaves out of `required`.

The output is source you paste into a project that already depends on Zod; the page ships no runtime.

What it does, and what it does not

Each JSON Schema type maps to one Zod constructor: string, number, integer (`z.number().int()`), boolean, null, array and object. An enum becomes `z.enum([...])` with the schema's own values.

Nested objects are written inline, indented by depth, because Zod composes by nesting. A nested object with a title still becomes an inline object: a named export would be a second declaration you did not ask for.

`$ref`, `oneOf`, `anyOf`, `allOf`, `not`, `if` and `patternProperties` are refused by name. Constraints beyond type and requiredness — `minLength`, `pattern`, `format` — are not emitted, so the validator is looser than the schema.

How to use JSON Schema to Zod

Paste the schema into the JSON Schema box, or press Run with the example already there.

Read the Zod schema below: the root is one exported `z.object`, with nested objects indented inside it.

Check an optional property in the Zod schema — it carries `.optional()`, and a required one does not.

What to Expect

Best for

  • Turning an existing JSON Schema into a runtime validator
  • Checking which fields the schema makes optional

Not ideal for

  • Enforcing a pattern or a string format, which is not emitted
  • Schemas that use $ref

What this tool keeps

  • Required versus optional on every property
  • Integer as an integer check, not a number check

What may need cleanup

  • Add `.min()` or `.regex()` where the schema had a constraint
  • Inline a $ref before pasting

Common errors

  • The page refuses it: uses anyOf, which this page does not model

Example use cases

  • Adding validation to a form from a schema
  • Replacing a hand-written validator with the schema's shape

Sample input

JSON Schema: { …

Sample output

Zod schema: import { z } from "zod"; …

Who this is for

  • TypeScript developers using Zod
  • Anyone validating data that arrives from a partner

Frequently asked questions

Does an optional property accept null?

No. .optional() accepts an absent key, not an explicit null. A schema that allows both needs a .nullable() you add by hand, because the page does not infer it.

Why is an integer not `z.number()`?

z.number().int() rejects a fractional value, which is what integer means. A plain z.number() would accept 1.5 on a field the schema types as an integer.

Are nested objects named?

No. Zod composes by nesting, so a nested object is written inline. A named export would be a second declaration the schema did not ask for.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.