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.

POSTGEThttps://apibox.io.vn/v1/schema-convert

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

NameInTypeRequiredDefault
schemabodyobjectyesJSON Schema (object, or JSON / YAML text; max 3 MB). Or a file / url.
tobody|querystringnotypescripttypescript, zod, pydantic, 2020-12, 2019-09, draft-07, draft-06, draft-04, openapi-3.0, json-schema, bundle or dereference.
frombody|querystringnoSource dialect if $schema is missing: draft-04 … 2020-12 or openapi-3.0 (auto-detected).
namebody|querystringnoName of the root type (default: title or Root).
refsbodyobjectnoExternal documents for $ref, keyed by URI or file name.
fetchbody|querybooleanno1: download http(s) $ref targets (max 20).
circularbody|querystringnorefdereference: ref (keep cycles as $ref) or error.
formatquerystringnotext: 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"}'

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

Start with 1,000 free requests every month. Get free API key →