How to use the JSON Schema to TypeScript
- Paste your JSON Schema — or an OpenAPI
components.schemasobject — on the left. - Set the root type name and whether to use
interfaceortype. - The TypeScript types update as you type; definitions under
$defsordefinitionsbecome their own named types. - Copy the code into a
.tsor.d.tsfile.
How JSON Schema maps to TypeScript
| JSON Schema | TypeScript |
|---|---|
"type": "string" / number, integer / boolean / null | string / number / boolean / null |
properties + required | interface with prop and optional prop? |
enum, const | literal union: "draft" | "published" |
items, prefixItems | T[], tuples [A, B] |
additionalProperties (schema) | index signature [key: string]: T |
oneOf / anyOf / allOf | A | B / A | B / A & B |
$ref: "#/$defs/User" | the named type User |
"type": ["string", "null"] | string | null |
Validation-only keywords such as minLength, pattern or format have no TypeScript equivalent; they are added to the JSDoc comment when JSDoc is on. External $ref URLs are typed as unknown.
Starting from example data instead of a schema? Use JSON to TypeScript. To check data against a schema, use the JSON Schema Validator.
Also searched as: json schema to ts, generate typescript from json schema, json schema interface, json-schema-to-typescript online, openapi schema to typescript, json schema types, json schema converter.
Tools that pair well with the JSON Schema to TypeScript
- JSON to Types — Paste an API response and get ready-to-use models in 8 languages: TypeScript, Python (dataclass, TypedDict or Pydantic), Go, Java, C#, Kotlin, Swift and Rust.
- JSON Formatter — Paste JSON to pretty-print, minify or validate it.
- JSON5 to JSON Converter — Paste JSON5 or JSON with comments (JSONC, like tsconfig.json or VS Code settings) and get strict, valid JSON.
- JSONPath Tester — Type a JSONPath query and instantly see what it selects — with the exact path of each match.