Skip to content

JSON Schema to TypeScript

Convert a JSON Schema into TypeScript types. Objects become interfaces with required and optional properties, $defs and definitions become named exports that $ref points to, enum and const become literal types, anyOf and oneOf become unions and allOf becomes an intersection. Descriptions are kept as doc comments.

Reset

Frequently asked questions

Which JSON Schema drafts are supported?

The converter reads the keywords shared by draft-07, 2019-09 and 2020-12: type, properties, required, additionalProperties, items, prefixItems, enum, const, anyOf, oneOf, allOf and $ref to $defs or definitions. Validation keywords such as minLength or pattern have no TypeScript equivalent and are left out.

How are $ref references resolved?

References to #, #/$defs/Name and #/definitions/Name become the named type of that definition. Any other reference, such as one to another file or a URL, is typed as unknown and listed in a comment at the top of the output.

How is additionalProperties handled?

An object with no properties and an additionalProperties schema becomes Record<string, T>. An object with properties and an additionalProperties schema becomes the interface joined with Record<string, T>. additionalProperties false or a missing keyword adds nothing, because TypeScript object types already describe the known keys.

What does nullable do?

The OpenAPI 3.0 nullable: true keyword and the Swagger x-nullable extension add | null to the type. In JSON Schema itself, write type: ["string", "null"], which becomes string | null.

Are recursive schemas supported?

Yes. A definition that refers to itself or to another definition through $ref becomes a named type that refers to the other name, which TypeScript resolves without problems.

Does it check that my schema is valid?

It only reads the schema. Unknown keywords are ignored and a schema without a type becomes unknown. Use the JSON Schema Validator to check data against a schema.

About OneClick Pro

OneClick Pro is a free collection of more than 150 web tools for everyday work: converting images and units, formatting and validating code, checking domains and SEO, and working with text, dates and numbers. Every tool runs without registration or subscription, and what you enter is only used to calculate your result and is never stored. Use it as a quick toolbox for one-off tasks, or bookmark the tools you rely on every day.