JSON Schema Generator
Developer Tools · Added
A schema describes a set of documents; a sample is one member of that set. Inference is therefore guesswork, and the difference between a useful guess and a useless one is being explicit about which guesses were made. This generates a schema in draft 2020-12 or draft-07, merges array elements rather than taking the first as the pattern, detects string formats conservatively, and lists every assumption underneath so you know what to edit.
How to use the json schema generator
- 1Paste a representative JSON document — one that includes the optional fields you care about.
- 2Choose the draft: 2020-12 is current, draft-07 has the widest tool support.
- 3Decide whether every property present should be marked required, which is the strictest reading of one sample.
- 4Turn on strict objects to forbid properties the sample did not contain.
- 5Read the assumptions list before using the output as a contract — it names every place a judgement was made.
Examples
A simple object
- Input
- {"name": "Ada", "active": true}
- Result
- An object schema with a string and a boolean, both required
One document cannot show which properties are optional, so all of them are required by default.
Format detection
- Input
- {"signedUpAt": "2026-03-14T09:30:00Z"}
- Result
- A string with "format": "date-time"
Detected conservatively: only unambiguous patterns get a format, because a wrong one rejects valid data.
An array with differing objects
- Input
- [{"a": 1}, {"a": 1, "b": 2}]
- Result
- Both properties appear, but only "a" is required
Every element is inspected and merged. Taking the first as the pattern would have missed "b" entirely.
About the json schema generator
What a schema is for
The obvious use is validation: checking that a payload arriving at an API boundary is the shape the code expects, and rejecting it with a useful message when it is not. That is worth doing at exactly one place — the edge — because everything inside can then assume the data is well-formed, which removes a great deal of defensive checking from the rest of the codebase.
The less obvious uses are often the more valuable. A schema is machine-readable documentation, so it can generate API reference pages that cannot drift from the implementation. It can drive form generation, since a description of the fields and their constraints is most of what a form needs. It can produce realistic test fixtures. And several tools generate client libraries in various languages directly from it.
It is also a communication artefact between teams. An agreed schema is a contract that can be versioned, reviewed and tested against, which is a considerably better basis for an integration than a sample payload pasted into a chat message — which is, in practice, what a schema is usually replacing.
Editing the generated schema
Treat the output as a first draft rather than a finished artefact. The generator can see structure and it cannot see intent, so everything that matters about business rules has to be added by hand.
The first pass is usually the required arrays: work through them and remove anything genuinely optional. The second is constraints the sample cannot imply — a `minimum` and `maximum` on a numeric field, an `enum` where only certain values are legal, a `pattern` on a string with a defined shape, `minItems` on an array that must not be empty. These are the checks that catch real bad data, and none of them is derivable from one valid document.
Finally, consider structure. A deeply nested schema is hard to read and harder to maintain, and the usual remedy is to pull repeated shapes into `$defs` and reference them with `$ref`. That also makes reuse possible across several schemas that share a definition of, say, an address or a monetary amount — which is where a schema stops being a validation detail and starts being part of how a system is described.
Frequently asked questions
Why is every property marked required by default?
How are arrays handled?
Why did my 2.0 become an integer?
Which draft should I choose?
How is this different from generating TypeScript types?
Related tools
JSON to TypeScript Generator
Developer Tools
Turn a JSON sample into TypeScript interfaces, with optional and union types inferred.
JSON Validator
Developer Tools
Check JSON validity and get a structural summary — depth, key count and type breakdown.
JSON Formatter
Developer Tools
Pretty-print, minify and inspect JSON with precise error positions.