JSON Schema to TypeScript Converter
Convert JSON Schema definitions to TypeScript interfaces — $ref, allOf, oneOf, enums, nested objects
Options
1,262 characters
5 types generated · 525 characters
You have a JSON Schema defining your API contract, and now you need TypeScript types that match it. Manually translating a 200-line schema with $ref, allOf, oneOf, nested objects, and string enums into TypeScript interfaces takes time and introduces errors whenever the schema changes.
What Is JSON Schema to TypeScript Conversion?
JSON Schema is a declarative vocabulary for describing JSON data structure and validation rules. TypeScript interfaces describe the shape of JavaScript objects at compile time. Converting between them bridges the gap between API contracts (runtime) and application code (compile time), ensuring your TypeScript types match the data your API actually sends.
How This Converter Works
Paste a valid JSON Schema (draft-07 or 2020-12) and the tool generates TypeScript interfaces:
- Object schemas:
type: "object"withpropertiesbecomes a TypeScript interface with matching fields - Required vs optional: Properties listed in
requiredbecome required fields; others get? - $ref resolution: Internal
$refreferences like#/$defs/Addressare resolved and generate separate named interfaces - allOf: Combines schemas using TypeScript intersection types (
A & B) - oneOf / anyOf: Generates TypeScript union types (
A | B) - Enums:
enum: ["active", "pending"]becomes"active" | "pending"union literal type - Arrays:
type: "array"withitemsbecomesItemType[] - Nested objects: Inline object schemas become nested interfaces or inline object types
Common Use Cases
OpenAPI code generation — OpenAPI specs define request/response schemas as JSON Schema. Convert those schemas to TypeScript interfaces for type-safe API client code.
Config file types — JSON Schema is used by VS Code, ESLint, and other tools for config validation. Generate TypeScript types from those schemas to type your configuration objects.
Database model types — If your database schema is expressed as JSON Schema (common with MongoDB validation), generate TypeScript interfaces for your data access layer.
API contract testing — Keep your TypeScript types in sync with your API schema by regenerating interfaces whenever the schema changes.
Working with the Output
After generating, you may want to:
- Rename interfaces: The generator uses schema
titleor$defskey names. Rename to match your project conventions. - Add utility types: Wrap generated types with
Partial<T>,Pick<T, K>, orOmit<T, K>for specific use cases. - Export types: Add
exportto interfaces you need to share across modules.
Frequently Asked Questions
Q: Which JSON Schema drafts are supported?
A: The converter supports draft-07 (the most widely used) and draft 2020-12. Core keywords like properties, required, $ref, allOf, oneOf, anyOf, enum, and type are fully handled in both drafts.
Q: How are circular $ref references handled? A: Circular references are detected and resolved by generating a named interface for the referenced schema, then using the interface name as the type. This avoids infinite recursion.
Q: Can I convert multiple schemas at once?
A: Paste a schema with $defs (or definitions) containing multiple sub-schemas and the tool generates a separate TypeScript interface for each one, plus the root type.
Q: Is my schema sent to a server? A: No. All parsing and TypeScript generation happens entirely in your browser. No data leaves your device.