JSON Schema to TypeScript
Compile JSON Schema into TypeScript interfaces. $ref, allOf, anyOf, oneOf, enum and tuples are handled; unsupported keywords are listed.
JSON Schema
TypeScript
Paste a JSON Schema to get TypeScript
Results update as you type. Nothing leaves your browser.
Examples
Required vs optional with a union
{ "type": "object", "required": ["id"], "properties": { "id": { "type": "integer" }, "value": { "anyOf": [{ "type": "string" }, { "type": "number" }] } } }export interface Root {
id: number;
value?: string | number;
}Listed required keys lose the ?, unlisted keys gain it, and anyOf branches join with |.
Cyclic $ref plus a string map
{ "type": "object", "properties": { "node": { "$ref": "#/$defs/Node" } }, "additionalProperties": { "type": "string" }, "$defs": { "Node": { "type": "object", "required": ["next"], "properties": { "next": { "$ref": "#/$defs/Node" } } } } }export interface Node {
next: Node;
}
[key: string]: string;Node emits exactly once with next: Node, and additionalProperties becomes an index signature.
About this tool
JSON Schema to TypeScript compiles a JSON Schema object into TypeScript interfaces with compileJsonSchemaToTypescript, defaulting the root to export interface Root. Object properties are emitted in sorted key order with required entries as name: T and everything else as name?: T, descriptions become /** */ doc comments, and integer maps to number. Unions come from anyOf/oneOf (joined with |), string|number style type arrays, enum string literals, and const values, while arrays render as T[] or Array<A | B> when the item type is itself a union.
References resolve through $defs and definitions: $ref values shaped like #/$defs/Name or #/definitions/Name (with ~0/~1 unescaping) emit one interface per target name, and # points back at the root. Cyclic graphs terminate because emit tracks an active set — a self-referencing Node with required next: $ref Node renders once as next: Node rather than expanding forever. Plain objects without an explicit type still emit interfaces when they carry properties or $defs, while additionalProperties: true yields [key: string]: unknown and an object schema value yields the resolved value type.
Validation runs before emission and fails loudly: non-object input throws Schema must be a JSON object, compileJsonSchemaJson throws Schema is not valid JSON on unparseable text, unknown type strings throw Invalid schema: unsupported type at <path>, and malformed properties, required, anyOf/oneOf, or $defs entries report their JSON-pointer path. Identifier sanitizing strips non-identifier characters and prefixes digit-leading names, so output is deterministic regardless of property insertion order.
How to use this tool
Paste a schema
Supply a JSON object schema with type, properties, required, and optionally $defs. Click compile or call compileJsonSchemaToTypescript(schema) to get the Root interface plus one interface per definition.
Model unions and maps
Use anyOf/oneOf for unions, enum for literal unions, type arrays for nullable shapes, and additionalProperties for string-keyed maps that render as [key: string]: T.
Wire up $refs
Point $ref at #/$defs/Name, #/definitions/Name, or # for the root. Cyclic refs are safe: the target renders once and referrers use its alias name.
Read the errors
Unsupported types, non-object properties, and bad required/anyOf shapes throw with a path (e.g. $.address). Fix the reported node instead of guessing.
Use cases
Typing API responses
Turn an endpoint's JSON Schema into Root plus named definition interfaces for request/response payloads.
Modeling recursive data
Express trees and linked structures with self-referencing $defs entries that compile to alias references instead of infinite nesting.
Documenting config shapes
Convert hand-written schemas with descriptions, enums, and string maps into commented interfaces for config files.
Common mistakes
Mistake:Expecting optional fields to be required.
Fix:Only keys listed in required lose the ?. Add the key to required when the field must always be present.
Mistake:Passing a JSON string to compileJsonSchemaToTypescript.
Fix:That function takes an object; pass raw text to compileJsonSchemaJson instead, which parses then compiles and throws Schema is not valid JSON on bad input.
Mistake:Using an unsupported type name.
Fix:Stick to array, boolean, integer, null, number, object, string. Anything else throws Invalid schema: unsupported type at the offending path.
Frequently asked questions
What does this tool do?
It compiles a JSON Schema object into TypeScript interfaces with compileJsonSchemaToTypescript (raw text via compileJsonSchemaJson): sorted properties, required keys without ? and optional keys with ?, anyOf/oneOf/enum/const unions, arrays, $ref aliases from $defs/definitions, and additionalProperties index signatures.
How do cyclic $refs, unions, and maps render?
A self-referencing $defs/Node entry emits once with next: Node instead of recursing; anyOf string|number renders value?: string | number; additionalProperties string renders [key: string]: string; and keys absent from required always gain ? (e.g. nickname?: string alongside id: number).
Is my schema uploaded or stored?
No. Compilation, $ref resolution, and validation are pure client-side computation — schemas never leave your browser.
Why did compilation throw?
Non-object input throws Schema must be a JSON object, bad JSON throws Schema is not valid JSON, and unknown types or malformed properties/required/anyOf nodes throw Invalid schema errors naming the $ path — fix the reported node.
Related guides
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.gitattributes Generator
Build .gitattributes rules for line endings, Git LFS, GitHub linguist marks and merge drivers — with a one-line explanation for every rule.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
A/B Test Sample Size Calculator
Compute required sample size per variant and test duration from baseline conversion rate, minimum detectable effect, alpha and power.
ABA Routing Number Validator
Validate 9-digit US ABA routing numbers with 3-7-1 Mod-10 breakdown.