Pure Frontend · Interface Convert · Type Inference · Union Types · Multi-format Export
Zero Dependencies · Works OfflineWhat Can TypeScript to JSON Schema Do?
The TypeScript to JSON Schema tool is a pure frontend online tool for converting TypeScript type definitions into JSON Schema. It supports interface, type aliases, enum, primitive types, arrays, nested objects, union types, optional properties, and literal types. The generated JSON Schema can be used for API documentation, form validation, code generation, and more. All conversion is done locally in your browser — data is never uploaded to any server.
Core Features
- Interface Conversion: Converts TypeScript interface to JSON Schema object type, automatically extracting required fields
- Type Aliases: Supports type definition conversion including union types, intersection types, and literal types
- Enum Support: Converts TypeScript enum to JSON Schema enum array
- Union Types: Literal unions become enum, type unions become oneOf
- Nested Objects: Recursively converts nested interface and type references
How to Use
Step 1: Select JSON Schema version (Draft 2020-12 or Draft 7).
Step 2: Enter TypeScript type definitions in the text area, or click "Load Example".
Step 3: Click "Convert Schema" or use Ctrl+Enter to view the generated JSON Schema.
Step 4: Click "Copy Schema" to copy to clipboard, or "Download JSON" to save as a file.
Use Cases
API Documentation
Convert TypeScript interface definitions to JSON Schema for OpenAPI/Swagger documentation generation, ensuring frontend-backend type consistency.
Form Validation
Use JSON Schema to drive frontend form validation (e.g., ajv, jsonschema libraries), auto-generating validation rules from TypeScript types.
Code Generation
Generate JSON Schema from TypeScript types, then use it to generate type definitions in other languages, mock data, or documentation.
Config Validation
Convert config file TypeScript types to JSON Schema for validating JSON/YAML configuration files.
Extended Knowledge
JSON Schema is a standard for describing JSON data structures, with the latest version being Draft 2020-12. TypeScript's type system has a natural correspondence with JSON Schema: string maps to {"type":"string"}, number maps to {"type":"number"}, interface maps to {"type":"object","properties":{...}}. Optional properties prop?: type are excluded from the required array. Union type 'a'|'b' becomes {"enum":["a","b"]}, string|number becomes {"oneOf":[{"type":"string"},{"type":"number"}]}. Array Type[] becomes {"type":"array","items":{...}}.
FAQ
Which TypeScript types are supported?
Supports interface, type aliases, enum, primitive types (string/number/boolean), arrays, nested objects, union types, optional properties, and literal types.
Is my data uploaded to a server?
No. All TypeScript parsing and JSON Schema generation is done locally in your browser. Your data is never uploaded to any server.
Are union types supported?
Yes. Union types are converted to JSON Schema's oneOf or enum structures, e.g., type Status = 'active' | 'inactive' becomes an enum array.
Can it handle nested objects?
Yes. Nested objects are recursively converted to JSON Schema's properties and required structures, supporting multiple nesting levels.
What JSON Schema version is generated?
Default is JSON Schema Draft 2020-12, with Draft 7 also available as an option.
Can I export the results?
Yes. You can copy the JSON Schema to clipboard or download as a JSON file.
Feedback: dexshuang@google.com