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 Schema | Generated 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
- 1Paste a JSON Schema (draft-07 or 2020-12) into the input.
- 2Optionally set a root type name — it's used when the schema has no "title" of its own.
- 3Click Convert — every definition under $defs/definitions becomes its own named interface, and the root schema becomes the final exported type.
- 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 contracts — Turn a request or response JSON Schema into the types your client and server share.
- ▸Config validation — Generate a type for a config file that's already described by a JSON Schema.
- ▸Form and data models — Create TypeScript models from schemas used by form builders or validation layers.
- ▸Keeping types in sync — Regenerate interfaces whenever the source schema changes so types never drift.
- ▸Documenting a public API — Publish 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.