TypeScript to JSON Schema Converter
Convert TypeScript interfaces, types, and enums to JSON Schema format. Perfect for API validation, documentation generation, and schema-based tools.
Schema Options
Recommended Settings
Supported TypeScript Features
- •Interfaces with properties, optional fields (?), and readonly
- •Type aliases for objects, unions, and literals
- •Enums with string and number values
- •Arrays (T[], Array<T>) and nested objects
- •Union types (string | number) converted to anyOf
- •Literal types ('success' | 'error') converted to enums
JSON Schema Features
- •Multiple schema versions (Draft-04, Draft-07, 2019-09, 2020-12)
- •Required vs optional property handling
- •Additional properties control (allow/deny)
- •Type mapping: string, number, boolean, null, arrays, objects
- •ReadOnly properties marked with readOnly: true
- •Date types converted to string with date-time format
Pro Tips
- •Optional properties (?) are excluded from required array unless 'Mark all as required' is enabled
- •Union types like 'string | number' are converted to anyOf schemas
- •Readonly properties are marked with readOnly: true in the schema
- •Conversion happens client-side - your TypeScript code never leaves your browser
Most Popular
Draft-07 schema with $schema property and strict additional properties
When to Use This Tool
Generate JSON Schemas from TypeScript API types for request/response validation. Use with tools like Ajv, joi, or express-validator to validate API payloads against your TypeScript contracts at runtime.
Convert TypeScript interfaces to JSON Schemas for OpenAPI/Swagger documentation. Generate accurate API docs that match your TypeScript types, ensuring documentation stays in sync with code.
Use JSON Schemas to auto-generate forms with libraries like react-jsonschema-form or Formik. Convert your TypeScript data models to schemas that define form structure, validation rules, and UI hints.
Validate data at runtime using JSON Schema validators. Convert TypeScript interfaces to schemas for validating user input, API responses, or configuration files against your type definitions.
Feed JSON Schemas into tools that generate code, tests, or documentation. Convert TypeScript types to schemas for use with code generators, mock data generators, or testing tools that consume JSON Schema.
Validate configuration files against TypeScript config interfaces. Convert your config types to JSON Schema to validate JSON/YAML configs in editors with IntelliSense and error checking.
How It Works
Paste TypeScript interface, type alias, or enum into input
Tool parses TypeScript syntax to extract type information
Properties are analyzed for types, optionality, and readonly status
TypeScript types are mapped to JSON Schema types (string, number, etc.)
Optional properties (?) are excluded from required array
Union types (A | B) are converted to anyOf schemas
Arrays and nested objects are recursively converted
Schema version and options are applied ($schema, additionalProperties)
Output formatted as valid JSON Schema with proper indentation
Copy schema or download as .json file
100% Private
Files never leave your device. All processing happens locally in your browser.
Lightning Fast
Powered by Pure JavaScript for optimal performance on modern browsers.
Secure
No data collection, no tracking, no sign-up required.
Frequently Asked Questions
What TypeScript features are supported?
Supports interfaces, type aliases, enums, basic types (string, number, boolean, null), arrays (T[], Array<T>), optional properties (?), readonly properties, nested objects, union types (string | number), and literal types ('success' | 'error'). Does NOT support generics, conditional types, mapped types, or utility types like Pick/Omit.
How are optional properties handled?
Properties marked with '?' in TypeScript are excluded from the 'required' array in the JSON Schema, making them optional. Enable 'Mark all properties as required' to override this and mark every property as required regardless of the '?' modifier.
What JSON Schema version should I use?
Draft-07 is recommended as it's widely supported by most tools and validators. Draft-04 is older but still common. 2019-09 and 2020-12 are newer with more features but have less tooling support. Most validation libraries support Draft-07.
How are union types converted?
TypeScript union types like 'string | number' are converted to JSON Schema 'anyOf' with an array of possible types. Literal unions like '"success" | "error"' are converted to an 'enum' array. This allows the schema to accept any of the specified types.
What does 'additionalProperties' control?
When disabled (default), the schema includes 'additionalProperties: false', meaning only defined properties are allowed. When enabled, objects can have extra properties beyond those defined in the TypeScript interface. This is stricter validation vs flexible validation.
Can I convert complex TypeScript types?
This tool supports common TypeScript patterns (interfaces, types, enums, unions, arrays, nested objects) but NOT advanced features like generics with constraints, conditional types, mapped types (Pick, Omit), or utility types. It covers ~80% of real-world use cases like API types and data models.
How are readonly properties handled?
TypeScript readonly properties are marked with 'readOnly: true' in the JSON Schema. This is a hint to validators and tools that the property should not be modified, though enforcement depends on the validator being used.
Is my TypeScript code sent to a server?
No! All conversion happens 100% client-side in your browser using JavaScript. Your TypeScript code never leaves your computer, is not sent to any server, and is not stored. The tool works completely offline after initial page load.