TypeScript Class to JSON Schema Generator

Need JSON to TypeScript?
JSON → TypeScript Types

TypeScript code Input

Loading editor…

JSON Schema Output

Settings

Select which interface/type should be treated as the JSON Schema root.

Parsing runs entirely in your browser. Your source never leaves the page.

Paste your TypeScript types to produce JSON Schema instantly.

Supports interfaces, type aliases, public class fields, optional/readonly modifiers, and union types.

How to convert TypeScript interfaces, types, and classes to JSON Schema – step-by-step guide

This online TypeScript interface to JSON Schema converter helps you generate JSON Schema from real models (DTOs, structs, and classes) so you can validate payloads, share contracts, and generate mock JSON.

  1. Step 1 – Paste your TypeScript source

    • Paste the models you want to document into the left editor.
    • Include referenced types in the same snippet so the schema can generate definitions.
    • Use the Sample button to load an example and see the expected input format.
  2. Step 2 – Select the Root type (if needed)

    • If multiple definitions are detected, choose the root that matches your API payload.
    • The output schema is built around the selected root and may include additional definitions for referenced types.
  3. Step 3 – Review the JSON Schema output

    • Check types, required vs. optional fields, and nested object/array structures.
    • Look for definitions and $ref when your models reference other models.
    • Copy or download the schema for validation, documentation, or schema-first development.
  4. Step 4 – Validate or generate mock JSON

    • Click Generate Mock Data to open the mock generator with your schema preloaded.
    • Validate real payloads against your schema to catch breaking changes early.
    • If you rely on advanced schema composition (for example anyOf/oneOf/allOf), verify the result with a full validator like Ajv.

Schema keyword support note

Generated schemas can include $ref and may be edited to include anyOf, oneOf, or allOf. For complex schemas, use a full JSON Schema validator and dereference before mock generation if needed.

Related JSON Schema & code generation tools

Use these tools to validate schemas, generate mock payloads, format JSON examples, and keep code and contracts in sync.

Frequently Asked Questions

What TypeScript syntax is supported?

Interfaces, type aliases, and classes with public fields are parsed. Optional properties, readonly modifiers, string-literal keys, union types, arrays, Record types, and nested references are handled. Comments and decorators are ignored so you can paste DTOs directly from your project.

How does type mapping work?

Primitive types (string, number, boolean, bigint, Date) map to JSON Schema primitives with appropriate formats. Arrays (Foo[] or Array<Foo>), Record<string, T>, and dictionary-like shapes become schema arrays/objects. Union types that include null/undefined automatically mark the field as optional.

Can I use it for classes as well as interfaces?

Yes. As long as the class defines public fields (or readonly properties) with type annotations, it will be converted into JSON Schema. The tool works entirely in your browser, so no code leaves your machine.

How do I get mock JSON from the schema?

After the schema is generated, click "Generate Mock Data" to open the Mock Generator with the schema preloaded. Configure locales, array sizes, and optional fields to produce sample payloads instantly.

TypeScript to JSON Schema Converter Online | JSONSwiss