Skip to content

jonashoyer/json-schema-to-zod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-schema-to-zod

Validate data with a JSON schema parsed to zod

Limited JSON schema support!

Only a few types are currently supported

  • Array
  • Object
  • Enum
  • String, Number, Integer, Boolean

Usage

import { parseJsonSchema } from "json-schema-to-zod";

const jsonSchema = {
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "productId": {
      "description": "The unique identifier for a product",
      "type": "integer"
    },
    "productName": {
      "description": "Name of the product",
      "type": "string"
    }
  },
  "required": [ "productId", "productName" ]
}

const zodSchema = parseJsonSchema(jsonSchema);
zodSchema.parse(data);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published