BYTETOOLS

JSON Schema to TypeScript

Convert JSON Schema to TypeScript interfaces online. Handles $ref, enum, oneOf, allOf, tuples and index signatures — 100% inside your browser.

Drop a schema .json file here or click to browse

What is the JSON Schema to TypeScript?

The ByteTools JSON Schema to TypeScript Converter turns a draft-07 or 2020-12 schema into ready-to-use TypeScript declarations.

  • Interfaces with optional ? members driven by required
  • enum and const become literal unions; oneOf/anyOf become unions
  • allOf becomes an intersection; array items become arrays or tuples
  • $ref into $defs or definitions resolves to a named type
  • additionalProperties becomes an index signature
  • description, format and default copied into JSDoc

How to use the JSON Schema to TypeScript

  1. 1

    Paste your JSON Schema into the input box, or drop a schema .json file onto the drop zone.

  2. 2

    Set the root type name, or leave it as Root.

  3. 3

    Tick 'Mark every property readonly' if your codebase prefers immutable models.

  4. 4

    Click Generate TypeScript, then Copy the declarations or Download them as a .d.ts file.

About the JSON Schema to TypeScript

The ByteTools JSON Schema to TypeScript Converter turns a draft-07 or 2020-12 schema into ready-to-use TypeScript declarations. Objects become interfaces with optional members for anything missing from required, enum becomes a union of literals, oneOf and anyOf become unions, allOf becomes an intersection, and array items become arrays or tuples.

References are resolved into named types. A $ref pointing into $defs or definitions produces a properly named interface that other types reuse, including recursive schemas that refer back to themselves. Every description, format and default is copied into a JSDoc comment above the member it belongs to.

Generation runs 100% locally in your browser. Your schema is never uploaded or stored, which makes the tool safe for unreleased API contracts and internal data models you cannot paste into a hosted service.

Frequently asked questions

How do I generate TypeScript types from a JSON Schema?

Paste the schema, give the root type a name and click Generate TypeScript. Interfaces for the root and every nested object appear below, ready to copy or download as a .d.ts file.

Which JSON Schema drafts are supported?

Draft-07 and 2020-12 in practice. The generator reads type, properties, required, enum, const, oneOf, anyOf, allOf, items, additionalProperties and $ref, which covers the great majority of real schemas.

How are $ref references handled?

A $ref pointing at #/$defs/Name or #/definitions/Name becomes a named interface reused everywhere it appears, and self-referencing schemas resolve to their own name rather than looping forever.

Why is a property optional when I expected it to be required?

Only names listed in the schema's required array become non-optional. If a property is missing from that array it gets a ? in the interface, because the schema itself says the value may be absent.

Does the generator validate data against the schema?

No. It only converts the schema's shape into TypeScript types. Constraints like minimum, maxLength or pattern have no TypeScript equivalent, so they are not enforced by the generated declarations.

Related tools