Zod to JSON Schema Converter

3.25.2 · deprecated · verified Sat Apr 18

Zod to Json Schema is a utility library (current stable version 3.25.2) designed to convert Zod schemas into JSON schemas. It supports various schema types, validations, and resolves recursive schemas using `$ref`s. However, this project is officially deprecated as of November 2025, recommending users transition to Zod v4, which offers native JSON schema generation.

Common errors

Warnings

Install

Imports

Quickstart

Converts a Zod object schema into a JSON schema, demonstrating basic type conversion, property validation, and the use of a schema name for `$ref` generation.

import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

const mySchema = z
  .object({
    myString: z.string().min(5),
    myUnion: z.union([z.number(), z.boolean()]),
  })
  .describe('My neat object schema');

const jsonSchema = zodToJsonSchema(mySchema, 'mySchema');

console.log(JSON.stringify(jsonSchema, null, 2));
/*
Expected output:
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/mySchema",
  "definitions": {
    "mySchema": {
      "description": "My neat object schema",
      "type": "object",
      "properties": {
        "myString": {
          "type": "string",
          "minLength": 5
        },
        "myUnion": {
          "type": [
            "number",
            "boolean"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "myString",
        "myUnion"
      ]
    }
  }
}
*/

view raw JSON →