Zod to JSON Schema Converter

Free online converterRuns locally in your browser
Input
Output
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "email": {
      "type": "string",
      "format": "email",
      "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
    },
    "role": {
      "type": "string",
      "enum": [
        "admin",
        "editor",
        "viewer"
      ]
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "profile": {
      "type": "object",
      "properties": {
        "website": {
          "anyOf": [
            {
              "type": "string",
              "format": "uri"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "website"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "id",
    "email",
    "role",
    "profile"
  ],
  "additionalProperties": false,
  "title": "UserSchema"
}
zod to json schema converter

Zod to JSON Schema Converter online

For the zod-to-json-schema search intent, this is the canonical FrameworkKit online converter: paste an inline Zod 4 schema and generate JSON Schema for Draft 2020-12, Draft 7, AJV validators, OpenAPI components, gateways, or schema registries. The browser workflow follows Zod's native z.toJSONSchema direction for supported schemas while adding examples, target switching, and diagnostics.

Supported Zod patterns

The safe converter subset covers the common schemas developers search for first: objects, strings, numbers, enums, literals, unions, arrays, optional fields, nullable fields, and nested objects.

  • z.object, z.strictObject, and z.looseObject.
  • z.string().email(), .url(), .uuid(), .min(), and .max().
  • z.number().int(), .min(), .max(), and nonnegative constraints.
  • z.enum, z.literal, z.union, z.array, .optional(), and .nullable().

Zod 4 native z.toJSONSchema vs npm zod-to-json-schema

Zod 4 ships native JSON Schema conversion through `z.toJSONSchema()`. FrameworkKit is the browser review workflow around that direction: paste a supported snippet, compare draft and OpenAPI output, and see diagnostics before copying. The npm zod-to-json-schema package is still useful when a repository script or CI job should generate schema files from committed Zod code.

Refine and transform diagnostics

Custom `.refine()`, `.superRefine()`, `.transform()`, `.pipe()`, and similar runtime callbacks are not portable JSON Schema rules. FrameworkKit keeps these cases visible as diagnostics so teams do not accidentally publish a schema that dropped business logic.

  • Keep custom refinements in a separate Zod validation step.
  • Represent simple constraints with built-in checks before using refine.
  • Use fixtures to compare the original Zod parser with the generated JSON Schema validator.

Enum, nullable, AJV, and OpenAPI examples

The highest-risk handoff details are enum values, nullable fields, object strictness, and draft selection. Use the examples page and AJV/OpenAPI guides to review each target before publishing schema output to a gateway, registry, or API document.

Privacy and safety

FrameworkKit does not execute pasted snippets. It parses supported Zod syntax, rejects unsafe patterns, and runs conversion in the browser so private schema code can be reviewed without a server upload.

OpenAPI and AJV workflows

Convert supported Zod 4 schemas for Draft 2020-12 or Draft 7 JSON Schema validators such as AJV, or switch on OpenAPI mode when you need nullable fields represented for OpenAPI 3.0.

FrameworkKit vs z.toJSONSchema and npm zod-to-json-schema

Use FrameworkKit for interactive online conversion, target comparison, AJV/OpenAPI review, shareable examples, and visible diagnostics. Use native z.toJSONSchema or the npm zod-to-json-schema package when conversion should run in CI, builds, tests, or synchronized repository scripts.

Zod to JSON Schema online converter

FrameworkKit is a browser-only zod-to-json-schema online converter for developers who need quick Draft 2020-12, Draft 7, OpenAPI 3.0, or AJV-ready output without wiring a script into the project first. It is built for Zod 4 workflows, including the native `z.toJSONSchema` direction, while keeping diagnostics visible before you copy the result.

Browser-only conversion

Paste supported Zod snippets, convert locally, and avoid uploading private schema code to a backend service.

No eval, visible diagnostics

FrameworkKit parses a safe inline subset, rejects executable snippets, and shows warnings before you copy output.

Draft, AJV, and OpenAPI targets

Generate Draft 2020-12, Draft 7, or OpenAPI-compatible schema output from the same Zod source.

Zod 4 and z.toJSONSchema

Use the same conversion direction as Zod 4 native JSON Schema output, with a UI for target switching.

How to convert Zod to JSON Schema

Start with a supported Zod 4 schema, choose the target your validator or API contract expects, then review the generated JSON Schema before publishing it to AJV, OpenAPI, gateways, or documentation.

1. Paste a Zod schema

Use an inline z.object, enum, union, array, optional, nullable, or nested schema snippet.

2. Pick the JSON Schema target

Select Draft 2020-12, Draft 7, or OpenAPI mode depending on the downstream validator.

3. Review and copy output

Check diagnostics for transforms, refinements, and Zod-only behavior before copying the schema.

Zod input and JSON Schema output

This is the core zod-to-json-schema workflow: keep Zod as the TypeScript source, then publish portable JSON Schema for systems that do not run Zod directly.

Zod schema input

const UserSchema = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  role: z.enum(["admin", "member"]),
  profile: z.object({
    website: z.string().url().nullable(),
  }).optional(),
});

JSON Schema output

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["id", "email", "role"],
  "properties": {
    "id": { "type": "string", "format": "uuid" },
    "email": { "type": "string", "format": "email" },
    "role": { "type": "string", "enum": ["admin", "member"] },
    "profile": {
      "type": "object",
      "properties": {
        "website": {
          "anyOf": [{ "type": "string", "format": "uri" }, { "type": "null" }]
        }
      }
    }
  },
  "additionalProperties": false
}

Zod to JSON Schema conversion examples

These examples show how common Zod patterns map into portable JSON Schema shapes before you decide whether to publish Draft 2020-12, Draft 7, OpenAPI, or AJV-oriented output.

PatternZod inputJSON Schema output shape
Object schemaz.object({ id: z.string().uuid(), email: z.string().email() })type object, required id and email, string formats uuid and email
Enum and literalz.object({ role: z.enum(["admin", "member"]), status: z.literal("active") })enum arrays for role and status, useful for validators and generated docs
Nullable and optionalz.object({ website: z.string().url().nullable().optional() })website omitted from required, with string or null value semantics
Nested arraysz.object({ teams: z.array(z.object({ members: z.array(z.string()) })) })nested items schemas for arrays of objects and arrays of strings
OpenAPI nullablez.object({ nickname: z.string().nullable() })OpenAPI 3.0 mode can emit nullable: true instead of a JSON Schema null union

FrameworkKit vs Zod native z.toJSONSchema vs npm zod-to-json-schema

Search results mix online converter, library, and official API intent. Use this comparison to decide whether a browser converter, native Zod call, or package workflow belongs in your project.

WorkflowBest forReview note
FrameworkKit converterOnline converter intent: interactive browser conversion, quick examples, OpenAPI mode, AJV draft comparison, and shareable snippets.Use when you want to inspect output before adding conversion to the codebase.
Zod native z.toJSONSchemaRepository scripts, tests, build steps, and schemas that should stay synchronized with source code.Best when the project already owns the Zod schema and conversion should run in CI.
npm zod-to-json-schema packageExisting projects that already depend on the package or need package-specific options.Use for package-driven automation, not quick online conversion. Review Zod 4 compatibility and target draft behavior before publishing contracts.

Zod to JSON Schema compatibility matrix

Zod patternJSON Schema resultReview note
Objects, arrays, enums, literalsObjects become properties and required arrays; enums and literals become enum constraints.Confirm strict, loose, and additionalProperties behavior before publishing.
String and number checksCommon checks map to format, pattern, minimum, maximum, minLength, and maxLength.Confirm validator support for formats when compiling with AJV.
Optional and nullable fieldsOptional fields are omitted from required; nullable fields use JSON Schema or OpenAPI nullable output.Choose Draft 2020-12, Draft 7, or OpenAPI mode before sharing schemas.
Transforms and refinementsCustom executable validation cannot be represented as plain JSON Schema.Keep those rules in Zod or model equivalent JSON Schema constraints manually.
AJV and OpenAPI workflowsThe same Zod source can produce validator-oriented JSON Schema or OpenAPI-compatible output.Pin the target draft and test valid, invalid, nullable, and extra-property fixtures.

AJV and OpenAPI mini workflows

The same reviewed output can feed different downstream systems. Pick the target first, then test fixtures against the generated schema before publishing it as a contract.

AJV validator handoff

Choose Draft 7 or Draft 2020-12, copy the JSON Schema, compile it with the matching Ajv setup, and test valid, invalid, nullable, optional, and extra-property payloads.

OpenAPI component handoff

Enable OpenAPI mode for OpenAPI 3.0 nullable output, then place the reviewed schema under components.schemas before wiring paths, request bodies, and responses.

Repository automation handoff

Use FrameworkKit to inspect output during design, then move stable conversions into z.toJSONSchema or package scripts when the schema source belongs in the repository.

What this tool does

Use an online converter to turn a Zod schema snippet into Draft 2020-12, Draft 7, AJV, or OpenAPI-compatible JSON Schema without uploading code.

Convert Zod 4 to JSON Schema

Turn a TypeScript-first runtime validator into a portable JSON Schema contract using Zod 4-compatible output.

Choose AJV schema drafts

Generate Draft 2020-12 or Draft 7 JSON Schema before compiling validators with AJV.

Prepare OpenAPI schema output

Switch to OpenAPI mode when nullable values need OpenAPI 3.0-compatible representation.

Zod to JSON Schema resources

Use the AJV guide, OpenAPI workflow, examples, and comparison pages when publishing Zod schemas as portable JSON Schema.

FAQ

Does Zod to JSON Schema execute my code?

No. FrameworkKit parses a safe subset of inline Zod syntax and then uses Zod's native JSON Schema converter. It does not eval pasted snippets.

Does this support Zod 4?

Yes. The converter is built around Zod 4's native `z.toJSONSchema()` behavior for supported schemas.

How is FrameworkKit different from calling z.toJSONSchema()?

FrameworkKit is an interactive browser workflow for quick conversion, examples, diagnostics, sharing, OpenAPI mode, and AJV-oriented draft output. Calling `z.toJSONSchema()` directly is better when conversion belongs in your codebase, build scripts, or tests.

Is this the npm zod-to-json-schema package?

No. FrameworkKit is an online converter for reviewing and copying supported schema output in the browser. Use the npm package or native Zod API when conversion should run inside a project script, build, or CI workflow.

Can transforms and refinements be converted?

Transforms, custom refinements, and executable validation logic do not have reliable JSON Schema equivalents, so the tool reports a diagnostic instead of pretending the output is complete.

Can I use the output with OpenAPI or AJV?

Yes for supported schema features. Use OpenAPI mode for OpenAPI 3.0 nullable output, or Draft 2020-12/Draft 7 for JSON Schema validators such as AJV.