JSON Schema Converter API
Convert JSON Schema to TypeScript, Zod or Pydantic, upgrade draft-04/06/07 to 2020-12, convert to and from OpenAPI 3.0, and bundle or dereference $ref.
Send a JSON Schema (object, JSON or YAML text, file or URL) and pick to. Code: typescript (interfaces / types with JSDoc), zod (schemas with min / max / regex / email / uuid / datetime refinements, .strict(), z.lazy for recursion, plus z.infer types) and pydantic (Pydantic v2 models with Field() constraints, aliases for non-identifier keys, extra="forbid"); definitions / $defs become named types.
Drafts: 2020-12, 2019-09, draft-07, draft-06, draft-04 upgrade or downgrade the schema (definitions ↔ $defs, id ↔ $id, boolean ↔ numeric exclusiveMinimum / Maximum, items array ↔ prefixItems, dependencies ↔ dependentRequired / dependentSchemas, const ↔ enum, keywords next to $ref). OpenAPI: openapi-3.0 turns JSON Schema into an OpenAPI 3.0 Schema Object (nullable, example, exclusive bounds, $defs → components.schemas); json-schema does the reverse and accepts a whole OpenAPI 3.0 (or Swagger 2.0) document. References: bundle pulls external $refs (from refs = {"common.json": {...}} or URLs with fetch=1) into $defs; dereference inlines every $ref and reports cycles (kept as $ref, or circular=error).
Whatever cannot be expressed in the target is listed in warnings. Related: /v1/json-to-types infers types from sample JSON, /v1/schema-mock makes example data, /v1/openapi-tools works on whole API documents. format=text returns only the code.
Markdown · OpenAPI · Postman · llms.txt
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
schema | body | object | yes | JSON Schema (object, or JSON / YAML text; max 3 MB). Or a file / url. | |
to | body|query | string | no | typescript | typescript, zod, pydantic, 2020-12, 2019-09, draft-07, draft-06, draft-04, openapi-3.0, json-schema, bundle or dereference. |
from | body|query | string | no | Source dialect if $schema is missing: draft-04 … 2020-12 or openapi-3.0 (auto-detected). | |
name | body|query | string | no | Name of the root type (default: title or Root). | |
refs | body | object | no | External documents for $ref, keyed by URI or file name. | |
fetch | body|query | boolean | no | 1: download http(s) $ref targets (max 20). | |
circular | body|query | string | no | ref | dereference: ref (keep cycles as $ref) or error. |
format | query | string | no | text: return only the generated code as text/plain. |
Example
curl -X POST "https://apibox.io.vn/v1/schema-convert" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"schema":{"title":"Order","type":"object","required":["id","items"],"properties":{"id":{"type":"string","format":"uuid"},"items":{"type":"array","minItems":1,"items":{"$ref":"#/$defs/Item"}},"note":{"type":["string","null"],"maxLength":500}},"$defs":{"Item":{"type":"object","required":["sku","qty"],"properties":{"sku":{"type":"string"},"qty":{"type":"integer","minimum":1}}}}},"to":"zod"}'const res = await fetch('https://apibox.io.vn/v1/schema-convert', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"schema": {
"title": "Order",
"type": "object",
"required": [
"id",
"items"
],
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"items": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/$defs/Item"
}
},
"note": {
"type": [
"string",
"null"
],
"maxLength": 500
}
},
"$defs": {
"Item": {
"type": "object",
"required": [
"sku",
"qty"
],
"properties": {
"sku": {
"type": "string"
},
"qty": {
"type": "integer",
"minimum": 1
}
}
}
}
},
"to": "zod"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/schema-convert",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"schema": {"title": "Order", "type": "object", "required": ["id", "items"], "properties": {"id": {"type": "string", "format": "uuid"}, "items": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/Item"}}, "note": {"type": ["string", "null"], "maxLength": 500}}, "$defs": {"Item": {"type": "object", "required": ["sku", "qty"], "properties": {"sku": {"type": "string"}, "qty": {"type": "integer", "minimum": 1}}}}}, "to": "zod"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/schema-convert');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"schema":{"title":"Order","type":"object","required":["id","items"],"properties":{"id":{"type":"string","format":"uuid"},"items":{"type":"array","minItems":1,"items":{"$ref":"#/$defs/Item"}},"note":{"type":["string","null"],"maxLength":500}},"$defs":{"Item":{"type":"object","required":["sku","qty"],"properties":{"sku":{"type":"string"},"qty":{"type":"integer","minimum":1}}}}},"to":"zod"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"to": "zod",
"language": "zod",
"code": "// Generated from JSON Schema by apibox.io.vn /v1/schema-convert\nimport { z } from 'zod';\n\nexport const ItemSchema = z.object({\n sku: z.string(),\n qty: z.number().int().gte(1),\n});\nexport type Item = z.infer<typeof ItemSchema>;\n\nexport const OrderSchema = z.object({\n id: z.string().uuid(),\n items: z.array(ItemSchema).min(1),\n note: z.string().max(500).nullable().optional(),\n});\nexport type Order = z.infer<typeof OrderSchema>;\n",
"types": [
"Order",
"Item"
],
"warnings": []
}
Use cases
- Generate TypeScript types and Zod validators from your API's JSON Schemas
- Move old draft-04 / draft-07 schemas to 2020-12 for modern validators
- Reuse JSON Schemas inside an OpenAPI 3.0 spec (and back)
- Build Pydantic models or self-contained schemas for LLM tool calling
FAQ
Which Zod version is generated?
The Zod 3 API (z.object, z.string().email()…), which Zod 4 still accepts.
Can it convert TypeScript to JSON Schema?
No, that needs the TypeScript compiler. Use JSON Schema as the source, or infer from sample data with json-to-types.
What happens with external $ref?
Pass the referenced documents in refs, or set fetch=1 to download public http(s) URLs (up to 20 documents).
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.