zod-to-json-schema is a utility library designed to convert Zod schemas into JSON schemas, supporting various features like `$ref` resolution for recursive and recurring schemas, targeting OpenAPI 3.0 specifications, and enabling OpenAPI strict mode. The library is currently at version 3.25.2 and has seen a steady release cadence with recent minor updates. However, it is officially deprecated as of November 2025, with active maintenance ceasing due to Zod v4's native support for JSON schema generation. Users are strongly advised to migrate to Zod v4's built-in `z.toJSONSchema()` function. While `zod-to-json-schema` supports Zod v4 as a peer dependency since v3.25, it still primarily expects Zod v3-style schemas for conversion, making it a transitional solution.
npm install zod-to-json-schemaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates converting a Zod object schema with various types (string, union, optional, nullable) into a JSON schema, explicitly naming the schema and setting the target JSON schema draft version and `additionalProperties` behavior.
Migrate Zod schemas to use Zod v4's native `.toJSONSchema()` method. Ensure your Zod version is `^4` and update conversion logic accordingly. Refer to Zod v4 documentation for details on its native JSON Schema conversion.
If staying on `zod-to-json-schema` temporarily, ensure your Zod schemas are compatible with Zod v3 patterns. If using Zod v4 features, consider migrating to Zod v4's native JSON Schema conversion instead of relying on this library.
If you intend to allow additional properties, explicitly set the `removeAdditionalStrategy` option to `'strict'` or add `.passthrough()` to your Zod object schemas. Conversely, if you want to strictly disallow them, `.strict()` on the Zod schema or `removeAdditionalStrategy: 'false'` can be used.
Be aware of this specific behavior if you enable Open AI strict mode. If this transformation is not desired, ensure Open AI strict mode is disabled in the `zodToJsonSchema` options or manually adjust the resulting schema.
Ensure the package is installed: `npm install zod-to-json-schema` or `yarn add zod-to-json-schema`. Verify the import path in your code.
Use ES module syntax: `import { zodToJsonSchema } from 'zod-to-json-schema';`. If in a CommonJS environment, check package.json `exports` or ensure your build system handles interoperability correctly. Note that `zod-to-json-schema` does ship CommonJS builds.Ensure your `zod` peer dependency is within the `^3.25.28 || ^4` range. If using Zod v4, ensure you are still providing schemas that are compatible with the expectations of `zod-to-json-schema` (primarily Zod v3-style) or consider migrating to Zod v4's native JSON schema conversion.