JSON Schema to TypeScript

Generate TypeScript interfaces from a JSON Schema.

JSON Schema to TypeScript generates ready-to-use TypeScript interfaces from a JSON Schema. It maps each property to its TypeScript type, marks non-required fields optional, turns enums into string-literal unions, handles arrays and nested objects, resolves $ref definitions into named interfaces, and carries property descriptions over as JSDoc comments. Everything runs locally in your browser.

  • Required vs optional fields handled correctly
  • Enums become string-literal unions; $defs become named interfaces
  • Arrays, nested objects, oneOf/anyOf, and const supported
  • 100% private — nothing is uploaded

Schema vs Sample

Generating types from a schema is more precise than inferring them from one JSON sample, because the schema declares exactly which fields are required, which are enums, and what the constraints are. If you only have example data, use JSON to TypeScript instead; to produce a schema in the first place, see the JSON Schema Generator.

The Type Mapping

JSON SchemaGenerated TypeScript
"type": "string"string
"type": "integer" / "number"number
"type": "boolean"boolean
"type": "array", "items": {...}T[]
"enum": ["a", "b"]"a" | "b"
"const": "fixed""fixed" (literal type)
"oneOf" / "anyOf"A | B | C (union type)
Property not in "required"field?: T (optional)
"$ref": "#/$defs/Address"Address (named interface reference)

How to Use It

  1. 1Paste a JSON Schema (draft-07 or 2020-12) into the input.
  2. 2Optionally set a root type name — it's used when the schema has no "title" of its own.
  3. 3Click Convert — every definition under $defs/definitions becomes its own named interface, and the root schema becomes the final exported type.
  4. 4Copy the TypeScript output straight into your project. Since it's generated from the schema itself, it stays exactly as strict as your validation layer.

Common Uses

  • API contractsTurn a request or response JSON Schema into the types your client and server share.
  • Config validationGenerate a type for a config file that's already described by a JSON Schema.
  • Form and data modelsCreate TypeScript models from schemas used by form builders or validation layers.
  • Keeping types in syncRegenerate interfaces whenever the source schema changes so types never drift.
  • Documenting a public APIPublish a JSON Schema alongside your API and let consumers generate their own client types from it.

Why Generate from a Schema Instead of a Sample

A single JSON example can only show you what one document happened to look like — it can't tell you which fields are guaranteed to be present, which values are actually allowed, or what a field's precise numeric bounds are. A schema encodes all of that explicitly, so the generated TypeScript is a faithful contract rather than a guess extrapolated from one snapshot. If your schema and your real API responses ever drift apart, that's a bug in your validation layer worth fixing — not something the generated types should silently paper over.

Frequently Asked Questions

Fields listed in the schema's 'required' array become required properties; every other property is marked optional with a ? in the generated interface.

Yes. Definitions under $defs or definitions are emitted as their own named interfaces, and $ref references resolve to those names.

An enum becomes a string-literal (or numeric) union type, and const becomes a single literal type, so invalid values are caught at compile time.

No. The conversion runs entirely in your browser. Nothing is sent to a server.

Yes — an inline nested object schema becomes an inline nested TypeScript object type, matching the same shape without needing a separate named interface.

Keywords that don't map cleanly to a TypeScript type (like complex conditional if/then/else logic) degrade gracefully to unknown rather than producing invalid TypeScript, so the output always compiles.

Related Tools