TypeScript to JSON Schema

Paste a TypeScript interface, type alias or enum and get the equivalent JSON Schema — optional properties, literal unions, nested objects, $refs and JSDoc constraints included. Runs in your browser, nothing is uploaded.

Try:
JSON Schema

Convert TypeScript types to JSON Schema in your browser

Paste a TypeScript interface, type alias, enum, or a bare object type and get a pretty-printed JSON Schema. The converter is built for common API and form-validation models: primitives, arrays, tuples, optional properties, string/number literal unions, nested objects, local type references, extends, object intersections, index signatures, Record<string, T>, and JSDoc descriptions/constraints.

Everything runs locally in WebAssembly. Your source types are not uploaded, and the output is plain JSON you can copy into validators, OpenAPI schemas, tests, or documentation.

Worked example

Input:

/** A user visible in the admin UI. */
interface User {
  id: number;
  email: string;
  role: "admin" | "editor" | "viewer";
  bio?: string;
}

With Root type set to User, Schema draft set to 2020-12, Mark non-optional members required on, and Allow extra properties off, the result is an object schema with id, email, role, and bio under properties, role as a string enum, required: ["id", "email", "role"], additionalProperties: false, and the JSDoc sentence as the schema description.

Controls

Limits and edge cases

This is a focused converter, not a full TypeScript compiler. It deliberately rejects constructs that need real type checking or cross-file resolution: generics, utility/mapped types such as Partial or Pick, keyof, typeof, indexed access, conditional types, imports, exports from other files, functions, methods, classes, namespaces, and decorators. Unsupported input returns a line-numbered error naming the construct instead of guessing.

References between declarations in the same paste are supported and emitted as $ref plus reachable $defs/definitions. Recursive local references are allowed. any and unknown become open schemas, never becomes an impossible schema, Date becomes a string with format: date-time, and bigint becomes integer.

FAQ

Is this the same as a TypeScript compiler based generator?

No. Compiler-based generators can resolve imports, generics, utility types, and complex inferred types. This tool intentionally handles a practical single-file subset that is small enough to run as a pure WebAssembly block. When a type needs the compiler, the tool says so rather than emitting a misleading schema.

How are optional properties handled?

A property marked with ? is omitted from the required array. A property whose type includes undefined is treated the same way. If you turn off Mark non-optional members required, the tool omits the required array entirely.

Can I choose Draft-07 instead of JSON Schema 2020-12?

Yes. Pick draft-07 in the schema draft control. The converter switches the $schema URL, uses definitions instead of $defs, and emits Draft-07 tuple keywords (items array plus additionalItems: false) instead of 2020-12 prefixItems.

What JSDoc tags become schema keywords?

Plain JSDoc text becomes description. Tags including @title, @format, @pattern, numeric/string/array bounds such as @minimum and @maxLength, @default, @example, @deprecated, @nullable, and @asType are mapped to matching JSON Schema keywords when Use JSDoc comments is enabled.

Why did a TypeScript type fail to convert?

The error message should include a line number and the unsupported construct. The most common causes are generics (Box<T>), utility types (Partial<User>), imports, methods, functions, or mapped/conditional types. Paste the resolved shape as an interface or object type literal to convert it here.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool typescript-to-json-schema 'interface User {
  id: number;
  name: string;
  role: "admin" | "editor" | "viewer";
  bio?: string;
}'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/typescript-to-json-schema/?typescript=interface%20User%20%7B%0A%20%20id%3A%20number%3B%0A%20%20name%3A%20string%3B%0A%20%20role%3A%20%22admin%22%20%7C%20%22editor%22%20%7C%20%22viewer%22%3B%0A%20%20bio%3F%3A%20string%3B%0A%7D&root_type=User&draft=2020-12&required=true&additional_properties=true&jsdoc=true

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.