Generate types from a contract
Paste a JSON Schema, choose a root type name, then generate a declaration file. A property listed in required becomes required; other declared properties remain optional. String enums become literal unions. Local references keep reusable and recursive definitions connected.
{"type":"object","required":["id"],"additionalProperties":false,"properties":{"id":{"type":"integer"},"role":{"enum":["admin","viewer"]}}}
export interface User {
id: number;
role?: "admin" | "viewer";
}
Review type boundaries
JSON Schema integers become TypeScript numbers. TypeScript cannot express an exact integer range or prove that a string is an email address. Schemas containing numeric literals that would change when converted to JavaScript numbers are rejected. Keep large identifiers as strings in the contract.
Allow extra properties when unspecified follows JSON Schema’s open-object default. Turning it off deliberately narrows generated declarations for objects without an explicit additional-properties policy. It does not change your source schema.
Use JSON Schema Validator for runtime data checks, or JSON to TypeScript when you only have an example payload. The generated code is text and is never executed here.
Compiler and dependency notices: third-party licenses.
Frequently asked questions
How is this different from JSON to TypeScript?
JSON to TypeScript infers a shape from sample values. This tool reads a JSON Schema contract: required fields, enums, unions, object properties, arrays and local references drive the declarations. A sample alone cannot establish every optional field or allowed value.
Can the generator load external schemas?
No. Only local fragment JSON Pointer references are accepted, including recursive definitions. File and HTTP resolution are disabled. Bundle related schemas into definitions or $defs before using the generator.
Does generated TypeScript enforce every schema rule?
No. TypeScript models static shapes and does not validate data at runtime. Formats, string patterns, numeric ranges, uniqueness, conditional schemas and exactly-one union rules still require a JSON Schema validator. Generation reports these limits instead of claiming full validation equivalence.
Which schema features are supported?
The generator supports common object, array, tuple, enum, const, union, intersection, required-field and local-reference features through json-schema-to-typescript-lite. Modern prefixItems tuples are normalized for the compiler. Dynamic references and named anchors are not supported. The input limit is 200,000 characters; large arrays are not expanded into unlimited tuple alternatives.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.