JSON to JSON Schema Generator
Paste a JSON sample and get a draft 2020-12 schema as you type. Required keys, integer vs number, nullable unions and nested $defs are inferred from every array element — all in your browser.
Runs entirely in your browser — your JSON is never uploaded.
Inference and schema emission run here in the tab — the JSON you paste never leaves the browser. A sample describes what it saw: keys absent from every record cannot be marked required, and a field can still be absent in the next response.
How to generate a JSON Schema from a sample
- Paste one or many examples A single object works, but an array of real responses is better: every element is sampled, so keys that only some records carry become optional instead of wrongly required.
- Name the root and pick an indent The schema title is used for the root object and for any nested type names. Two or four spaces controls the pretty-printed output.
- Choose how strict to be Reject unknown keys writes additionalProperties: false on every object, so a validator fails on fields the sample never showed. Turn it off for responses that gain fields over time.
- Copy or download the .schema.json The output is ready to drop into an editor setting, a CI validation step or a schema registry. Nothing was uploaded to get it.
What the generator decides for you
Turning a sample into a schema is mostly mechanical, but a few decisions decide whether the result accepts tomorrow's data or rejects it. This tool makes those decisions the same way the code generators on this site do: from evidence in the sample, never from a guess.
- Required means observed. A key is required only if every sampled element carries it. A single record is marked required in full, which is honest about how little evidence it had.
- Numbers widen safely. A whole number becomes
integer, but one fractional value widens the field tonumberso the schema keeps validating. - Mixed primitives become type arrays. A field that is a string in one record and null in another is emitted as
{ "type": ["string", "null"] }; mixtures involving objects useanyOf. - Nested objects get names. Repeated shapes are hoisted into
$defsand referenced with$ref, so the root reads top-down instead of as one deeply nested literal.
Where a sample stops being enough
A generated schema is a starting point, not a contract. It cannot know that a field holding 129.5 is a price and not a quantity, or that an ISO date string should carry a format: date-time rule. Add those four constraints by hand before you rely on the schema in CI.
- Which keys are truly required in every future response.
- Which numbers are money, and need a decimal or integer-minor-units rule.
- Which strings are dates, emails, UUIDs or URLs, and need a format.
- Which fields are enums rather than any string at all.
The same sampling rule matters when the underlying values are large integers: by the time JavaScript reads them, precision may already be gone. The guide to why JSON numbers lose precision explains what to watch for before you generate a schema from such a payload.