npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-zodify

v1.0.2

Published

Convert JSON Schema to Zod schemas at runtime - Supports Zod v3 and v4

Readme

Zodify

Convert JSON Schema to Zod schemas at runtime.

A lightweight TypeScript library that dynamically generates Zod schemas from JSON Schema definitions. Perfect for scenarios where schemas are stored in databases or need to be validated at runtime.

Features

  • 🚀 Dynamic Schema Generation - Convert JSON Schema to Zod on the fly
  • 🔄 Zod v3 & v4 Compatible - Uses your project's Zod version (peer dependency)
  • 📦 Zero Version Conflicts - No bundled Zod, avoids type mismatches
  • 🎯 Full Type Support - String, number, boolean, array, object, null
  • Rich Validations - Formats, patterns, min/max, enums, and more
  • 🔗 Combinators - Supports oneOf, anyOf, allOf
  • 📝 $ref Resolution - Basic support for local references

Installation

npm install zodify
# or
pnpm add zodify
# or
yarn add zodify

Note: Zod is a peer dependency. Make sure you have it installed:

npm install zod

Usage

Basic Conversion

import { jsonSchemaToZod } from 'zodify'

const schema = jsonSchemaToZod({
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number', minimum: 0 },
  },
  required: ['name', 'age'],
})

// Validate data
const result = schema.parse({ name: 'John', age: 30 })
console.log(result) // { name: 'John', age: 30 }

Using the Class API

import { JSONSchemaToZod } from 'zodify'

const zodSchema = JSONSchemaToZod.convert({
  type: 'string',
  format: 'email',
  minLength: 5,
})

zodSchema.parse('[email protected]') // ✅ Valid
zodSchema.parse('invalid') // ❌ Throws ZodError

Complex Objects

const userSchema = jsonSchemaToZod({
  type: 'object',
  properties: {
    id: { type: 'string', format: 'uuid' },
    email: { type: 'string', format: 'email' },
    profile: {
      type: 'object',
      properties: {
        firstName: { type: 'string' },
        lastName: { type: 'string' },
        age: { type: 'integer', minimum: 0, maximum: 150 },
      },
      required: ['firstName'],
    },
    tags: {
      type: 'array',
      items: { type: 'string' },
      minItems: 1,
    },
    status: {
      type: 'string',
      enum: ['active', 'inactive', 'pending'],
    },
  },
  required: ['id', 'email'],
})

Using Combinators

// oneOf - Value must match exactly one schema
const oneOfSchema = jsonSchemaToZod({
  oneOf: [
    { type: 'string' },
    { type: 'number' },
  ],
})

oneOfSchema.parse('hello') // ✅
oneOfSchema.parse(42) // ✅

// allOf - Value must match all schemas (intersection)
const allOfSchema = jsonSchemaToZod({
  allOf: [
    { type: 'object', properties: { a: { type: 'string' } }, required: ['a'] },
    { type: 'object', properties: { b: { type: 'number' } }, required: ['b'] },
  ],
})

allOfSchema.parse({ a: 'hello', b: 123 }) // ✅

Using $ref

const schemaWithRefs = jsonSchemaToZod({
  type: 'object',
  properties: {
    user: { $ref: '#/$defs/User' },
  },
  $defs: {
    User: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        email: { type: 'string', format: 'email' },
      },
      required: ['name', 'email'],
    },
  },
})

Options

const schema = jsonSchemaToZod(jsonSchema, {
  // Make all properties optional
  allOptional: true,
  
  // Allow unknown keys (passthrough)
  passthrough: true,
  
  // Provide external definitions for $ref resolution
  definitions: {
    MyType: { type: 'string' },
  },
})

Supported JSON Schema Features

Types

  • string - With formats: email, uri, uuid, date-time, date, time, ipv4, ipv6
  • number / integer - With min, max, multipleOf
  • boolean
  • array - With items, minItems, maxItems, tuples
  • object - With properties, required, additionalProperties
  • null

Validations

  • String: minLength, maxLength, pattern, format
  • Number: minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf
  • Array: minItems, maxItems, tuple support
  • Object: required, additionalProperties

Keywords

  • enum / const
  • nullable
  • default
  • description
  • oneOf / anyOf / allOf
  • $ref (local references)

Why Zodify?

Other JSON Schema to Zod converters either:

  • Generate code strings that require eval() (security risk)
  • Bundle their own Zod version causing type conflicts
  • Only work at build time, not runtime

Zodify uses your project's Zod instance as a peer dependency, ensuring:

  • ✅ No version conflicts
  • ✅ Full TypeScript support
  • ✅ Runtime conversion
  • ✅ No eval() needed

License

MIT