How to convert a schema to TypeScript
- Paste a JSON Schema on the left, open a file, or load one from your stash.
- Pick the declaration style and options. The TypeScript updates as you type.
- Copy the code or download it as a
.tsfile.
Objects become interfaces with required and optional (?) properties. enum and const become literal unions, oneOf/anyOf become unions and allOf becomes an intersection. prefixItems (or array-form items) become tuples, additionalProperties schemas become index signatures or Record, and "type": ["string", "null"] becomes string | null. Titles and descriptions turn into JSDoc comments.
Options
- interface / type
- Plain object schemas become
interfacedeclarations ortypealiases. Unions and other shapes are always type aliases. - export and readonly
- Prefix every declaration with
export, and mark properties and arraysreadonly. - Index signatures
- Adds
[key: string]: unknownto objects that allow extra properties.
FAQ
How are $ref and $defs handled?
Every entry in $defs or definitions becomes its own named type, and each $ref uses that name instead of copying the schema. That keeps the output short and makes recursive schemas work.
Why are open objects not given an index signature by default?
JSON Schema allows extra properties unless additionalProperties is false, but adding [key: string]: unknown everywhere makes types harder to use. Turn on the index signature option if you want that strictness.
Which keywords cannot be expressed in TypeScript?
Value constraints such as minLength, pattern, minimum and format have no type-level equivalent, and not, if/then/else and dependentSchemas are ignored. Use the Zod converter if you need runtime checks.