PureDevTools

JSON Schema to TypeScript Converter

Convert JSON Schema definitions to TypeScript interfaces — $ref, allOf, oneOf, enums, nested objects

All processing happens in your browser. No data is sent to any server.

Options

Output:

1,262 characters

5 types generated · 525 characters

Types generated: 5Output size: 525 charsMode: interface · export

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:

  1. Object schemas: type: "object" with properties becomes a TypeScript interface with matching fields
  2. Required vs optional: Properties listed in required become required fields; others get ?
  3. $ref resolution: Internal $ref references like #/$defs/Address are resolved and generate separate named interfaces
  4. allOf: Combines schemas using TypeScript intersection types (A & B)
  5. oneOf / anyOf: Generates TypeScript union types (A | B)
  6. Enums: enum: ["active", "pending"] becomes "active" | "pending" union literal type
  7. Arrays: type: "array" with items becomes ItemType[]
  8. 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:

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.

Related Tools

More Code Transforms