← 全部工具

json-schema-to-zod

热度 65 更新于 开发与构建

Converts JSON schema objects or files into Zod schemas

npmauto-collected

安装

npm
npm install -g json-schema-to-zod

通过 npm 安装。

Json-Schema-to-Zod

Notice of deprecation

As of March 2026, this project will no longer be actively maintained.

Thank you to all the contributors and sponsors throughout the years! So long, and thanks for all the fish.

Summary

A runtime package and CLI tool to convert JSON schema (draft 4+) objects or files into Zod schemas in the form of JavaScript code.

Before v2 it used prettier for formatting and json-refs to resolve schemas. To replicate the previous behaviour, please use their respective CLI tools.

Since v2 the CLI supports piped JSON.

Looking for the exact opposite? Check out zod-to-json-schema

Usage

Online

Just paste your JSON schemas here!

CLI

#### Simplest example

npm i -g json-schema-to-zod
json-schema-to-zod -i mySchema.json -o mySchema.ts

#### Example with $refs resolved and output formatted

npm i -g json-schema-to-zod json-refs prettier