JSON Schema to Zod examples
Convert a JSON Schema document into Zod validators and inferred TypeScript types in your browser.
Object with required, enum, and nullable fields
A typical JSON Schema object with required keys, an enum, formats, and a nullable field.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "User",
"type": "object",
"required": [
"id",
"email",
"role"
],
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"email": {
"type": "string",
"format": "email"
},
"role": {
"type": "string",
"enum": [
"admin",
"editor",
"viewer"
]
},
"nickname": {
"type": [
"string",
"null"
]
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
}Open exampleShared subschemas with $defs and $ref
A root schema that references reusable subschemas defined under $defs.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Order",
"type": "object",
"required": [
"id",
"items"
],
"properties": {
"id": {
"type": "string"
},
"customer": {
"$ref": "#/$defs/Customer"
},
"items": {
"type": "array",
"items": {
"$ref": "#/$defs/LineItem"
}
}
},
"$defs": {
"Customer": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"website": {
"type": "string",
"format": "uri"
}
}
},
"LineItem": {
"type": "object",
"required": [
"sku",
"quantity"
],
"properties": {
"sku": {
"type": "string"
},
"quantity": {
"type": "integer"
}
}
}
}
}Open exampleDraft 7 definitions
A Draft 7 document that keeps shared schemas under definitions instead of $defs.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Address": {
"type": "object",
"required": [
"city"
],
"properties": {
"street": {
"type": "string"
},
"city": {
"type": "string"
},
"zip": {
"type": "string"
}
}
}
}
}Open exampleUse these examples with guides
JSON Schema to Zod converter
Convert a JSON Schema document into Zod validators and inferred TypeScript types in the browser.
JSON Schema to Zod guide
Map JSON Schema keywords to Zod, resolve $ref and $defs, and review unsupported keyword diagnostics.
Zod to JSON Schema vs JSON Schema to Zod
Choose the right direction when moving between Zod schemas and portable JSON Schema contracts.
OpenAPI to Zod converter
Use the OpenAPI-aware converter when the source is an OpenAPI or Swagger document instead of raw JSON Schema.
Zod to JSON Schema Converter
Use the opposite direction when TypeScript-owned Zod schemas need portable JSON Schema output.