TypeScript to JSON Schema converter
Convert TypeScript to JSON Schema (2020-12): paste interfaces, types and enums and get a schema for each. extends, intersections, Pick/Omit/Partial, tuples, enums and recursive types are resolved exactly as TypeScript resolves them, and JSDoc tags such as @minLength become constraints.
What you get
- Convert a TypeScript interface to JSON Schema: type aliases, unions, enums, optional properties, and JSDoc rules like @minLength and @pattern.
- Proven by the TypeScript compiler: the JSON Schema from TypeScript describes exactly your types, in both directions.
- Private and free: everything runs in your browser, nothing is uploaded, and there is no sign-up.
How each result is checked
- Your code is read by the real TypeScript compiler. Type errors are reported with the line number.
- The schema is compiled with Ajv, the most widely used JSON Schema validator.
- Round trip: the schema is turned back into TypeScript, and the compiler must prove that every original type and its twin accept exactly the same values.
What can't convert exactly
- Put each JSDoc comment on its own line above the property it describes. TypeScript does not attach a /** */ comment written after other code on the same line, so its rules would not apply; the result names any such comment.
- Date, functions, bigint, Map and Set have no JSON form. Date becomes an ISO date-time string; the others are reported. Types using them are not part of the round-trip proof, and the result says which.
- Generic types such as Page<T> have no single schema; they are included wherever they are used with concrete types (for example Page<Item>).
- By default objects reject keys they do not declare (additionalProperties: false). Choose "Allow" if your data may carry extra keys.
- "a: T | undefined" becomes an optional key, because undefined never appears in JSON.
Questions
Which JSDoc tags are read?
minLength, maxLength, pattern, format, minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, minItems, maxItems, uniqueItems, default, examples and deprecated, plus the comment text as the description.
Are string enums handled?
Yes. A string enum becomes an enum of its values. The round trip compares values, so Color.Red and "red" count as the same.
How do I generate JSON Schema from TypeScript without a build step?
Paste your interfaces or type aliases here: you get ts to JSON Schema output (draft 2020-12) for every exported type, with JSDoc tags such as @minLength and @pattern as rules. The TypeScript compiler then proves the schema accepts exactly the values your types do.
How do I convert TypeScript to JSON Schema online?
Paste your TypeScript or open a file on the left (or click Example). The JSON Schema appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.
Can the JSON Schema output be wrong?
Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.