TypeScript Interface to JSON Schema Generator (Draft-07 & 2020-12)
TypeScript Schema Compiler

TypeScript Interface to JSON Schema Generator (Draft-07 & 2020-12)

Transform TypeScript interfaces, types, and JSDoc comments into standard JSON Schema definitions for API contracts and form builders.

Draft-07 & 2020-12 Conformance
Zero Server Transmission
Presets:
Draft Version:
Root Type:
Definitions Key:
Additional Properties:
Indentation:
TypeScript Interfaces & Types0 Types
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "EmptySchema",
  "type": "object",
  "properties": {}
}
Interfaces & Types
0AST parsed
JSON Schema Version
Draft 2020-12$defs
Properties & Rules
0rules synthesized

100% Client-Side AST Parsing

TypeScript interface extraction and schema compilation execute purely in your local browser sandbox. Zero data transmission or server logging.

Draft-07 & 2020-12 Conformance

Full compatibility with standard JSON Schema specifications including $defs/definitions, tuple prefixItems, strict typing, and enum generation.

JSDoc & Smart Constraint Inference

Extracts @description, @minimum, @maximum, @format, @pattern, @default directly from code comments to synthesize rich OpenAPI-grade schemas.

Technical Reference & Architecture Guide

TypeScript Interface to JSON Schema Generator (Draft-07 & 2020-12) — Reference Guide

Transform TypeScript interfaces, type aliases, and JSDoc comments into standard JSON Schema definitions for API contracts, Ajv validation, and form builders.

Key Parameters & Controls

targetDraftstring

Target JSON Schema specification dialect ('draft-07', '2020-12', or 'draft-04').

Default: draft-07
strictNullChecksboolean

Enables strict nullability handling, treating T | null and T | undefined distinctly in the resulting type array or anyOf clause.

Default: true
topRefboolean

Generates a root-level $ref pointing to the main interface definition in $defs or definitions.

Default: true
additionalPropertiesboolean

Determines whether generated object schemas disallow undeclared keys by setting 'additionalProperties: false'.

Default: false
extractCommentsboolean

Extracts JSDoc block comments and maps validation tags (@minimum, @maximum, @format, @pattern) directly to schema constraints.

Default: true

Pro Tips & Best Practices

Use standard JSDoc tags like

Use standard JSDoc tags like @minimum 1, @maximum 100, @pattern ^[a-z]+$, and @format email inside TypeScript interface comments to generate rich JSON Schema constraints without external validation decorators.

Draft-07 vs Draft 2020-12 Definitions

Draft-07 stores shared sub-interfaces inside the top-level 'definitions' keyword, whereas Draft 2020-12 standardizes this under '$defs'. Ensure your downstream validator (such as Ajv v8 or Python jsonschema) aligns with your chosen dialect.

Unions vs Discriminated Unions

Standard TypeScript unions (A | B) generate an anyOf structure, while discriminated unions featuring a shared literal tag property map cleanly to oneOf with const or enum discriminators for unambiguous schema validation.

Common Gotchas & Troubleshooting

Circular and Recursive Type References

Enable topRef and definition reuse mode so that recursive members point back to self-referential schema pointers (e.g., '#/$defs/TreeNode' or '#/definitions/TreeNode') instead of attempting inline unrolling.

Complex Mapped and Utility Types (Omit, Pick, Partial)

Pre-evaluate or normalize utility types into concrete interfaces, or declare explicit intermediate types rather than relying on deep runtime AST evaluation for dynamic conditional types.

Frequently Asked Questions

How does the generator handle optional fields (prop?: string)?▼

In TypeScript, optional properties denote fields that may be omitted. In JSON Schema, properties are optional by default unless listed in the 'required' string array. If strictNullChecks is active, 'prop?: string' excludes prop from 'required', while 'prop: string | null' keeps prop in 'required' but gives it type ['string', 'null'].

Which JSDoc tags are converted into JSON Schema validation rules?▼

The generator parses description comments into the 'description' keyword. Additionally, validation tags such as @minimum, @maximum, @minLength, @maxLength, @pattern, @format (e.g., uri, date-time, email, uuid), @default, and @deprecated are parsed directly into standard validation constraints.

What is the difference between Draft-07 and Draft 2020-12 output?▼

Draft-07 uses 'definitions' for reusable schemas and supports 'items' as an array for tuple validation. Draft 2020-12 uses '$defs', introduces 'prefixItems' for tuples, and allows $dynamicRef and independent keyword evaluation, making it ideal for modern API specifications and OpenAPI 3.1.

Can I convert multiple interfaces in a single TypeScript file?▼

Yes. When multiple interfaces or type aliases are present, you can designate a root interface name. All referenced types and nested interfaces will be generated as modular schema definitions under '$defs' or 'definitions', linked via relative $ref URIs.

Related Tools & Utilities

All Tools →