UTILS.
100% in-browser
📘

JSON Schema to TypeScript

Compile a JSON Schema (draft-07 or 2020-12) into TypeScript interfaces and type aliases, handling required, enums, $ref, arrays, and combinators.

output

About this tool

The JSON Schema to TypeScript tool compiles a JSON Schema document into TypeScript interfaces and type aliases, doing what the popular json-schema-to-typescript library does without installing a toolchain. Unlike the JSON-sample converters, this one reads an actual schema: it walks the schema object and turns type:'object' into an interface where keys listed in required are non-optional and the rest are marked with ?.

Everything is parsed and generated locally in your browser with JSON.parse and plain JavaScript, so your schema never leaves the page. String schemas with an enum become a union of string literals; plain string, number/integer, boolean, and null map to their TypeScript equivalents; arrays become T[] (a tuple when items is an array). Combinators are supported — allOf becomes an intersection (A & B) and anyOf / oneOf become unions (A | B) — and a nullable type:[T,'null'] becomes T | null.

References are resolved by name: $ref pointing at #/definitions/X or #/$defs/X emits a named type reference, and every definition is generated as its own export interface or export type. additionalProperties adds an index signature [key: string]: T. The root type name falls back to the schema's title or $id. Toggle interface-vs-type output and whether schema description strings become JSDoc /** */ comments. Copy the result or download a .ts file.

Frequently asked questions

Which JSON Schema features are supported?
object with properties and required, string enums as literal unions, number/integer/boolean/null, arrays (including tuples), allOf/anyOf/oneOf combinators, $ref to definitions or $defs, additionalProperties as an index signature, and nullable type arrays like ["string","null"].
How are $ref and definitions handled?
A $ref such as #/definitions/Address (or #/$defs/Address) becomes a reference to a named type Address, and each entry under definitions or $defs is emitted as its own export interface or export type, so the references resolve within the output.
What names the root type?
The root-name box if you set it, otherwise the schema's title, otherwise the last segment of its $id, otherwise Root. Definition names come from their key in definitions or $defs, converted to PascalCase.
Can I keep the schema descriptions?
Yes. With JSDoc on (default), any description string on the schema or a property is emitted as a /** ... */ comment above the corresponding type or field, preserving the documentation in the generated TypeScript.

More tools