Skip to content

JSON Schema Generator

Infer a Draft 2020-12 JSON Schema from sample structure with required presence, nullable values, arrays, mixed types, and explicit uncertainty.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Paste representative strict JSON and optionally enter a concise schema title.
  2. 2.Generate and inspect required fields, nullability, array items, anyOf branches, and open-object behavior.
  3. 3.Copy the schema and test positive and negative instances with a Draft 2020-12-capable production validator.

About JSON Schema Generator

JSON Schema Generator converts one strict JSON value into a readable structural schema declaring the Draft 2020-12 dialect. Paste a representative sample, add an optional title, generate, inspect, and copy. Parsing and inference stay in the current tab; the page does not upload data, run a validator, or contact a schema registry.

JSON strings, safe integers, other numbers, Booleans, and null map to their corresponding JSON Schema types. Arrays use items inferred from every observed element. Empty arrays emit an empty items schema because no element constraint can be justified. Mixed compatible numbers widen integer to number, while incompatible observed types become deterministic anyOf branches.

Objects emit type object, properties, and required. A property observed in every merged object sample is required. A property missing from at least one object is left out of required. Property names are preserved exactly, including punctuation and prototype-shaped spellings. The generator intentionally omits additionalProperties, leaving objects open because one sample cannot prove that unseen keys are forbidden.

Null combined with a directly typed schema adds null to the type array while retaining properties or items. More complex combinations use anyOf. Nested objects and arrays are inferred recursively. Duplicate equivalent branches are removed and output order is deterministic, so the same input produces stable text suitable for review and version control.

This is structural sample inference, not schema discovery. The generator does not guess format, pattern, enum, const, minimum, maximum, multipleOf, lengths, uniqueness, descriptions, defaults, examples, deprecation, readOnly, writeOnly, content encoding, references, anchors, IDs, conditional logic, unevaluated properties, or business meaning. Add them only from authoritative requirements.

The dialect URI is https://json-schema.org/draft/2020-12/schema. Validators must explicitly support that dialect, and format may be annotation-only unless the chosen implementation enables assertion behavior. Test the copied schema with the exact validator, configuration, and vocabulary used in production instead of assuming every library interprets every keyword identically.

Strict JSON is required, so comments, trailing commas, NaN, Infinity, undefined, BigInt, and JavaScript literals fail. JavaScript parses the sample number before inference; only safe integers become integer, avoiding a false exactness claim for larger rounded values. Precision-sensitive decimals and identifiers may need strings plus application validation.

Limits are 500,000 input characters, 50,000 values, 40 nesting levels, and 1,000,000 output characters. Boundary failures emit no partial schema. Eight external fixtures cover all primitives, empty and typed arrays, and merged object required fields. Additional tests cover nullable items, mixed anyOf arrays, special property names, and malformed JSON. Validate both accepted and rejected instances before publishing the result.

Methodology & sources

Parses strict JSON, recursively maps observed primitives, arrays and objects to Draft 2020-12 keywords, merges object presence into required, widens integer to number, represents incompatible evidence with anyOf, preserves nullability, leaves additionalProperties unspecified, and fails instead of truncating.

Frequently asked questions

Why is additionalProperties absent?
One sample cannot prove that unobserved keys are forbidden. The generated object remains open until your authoritative contract says otherwise.
Why are formats and enums not inferred?
A spelling or small sample is insufficient evidence for semantic constraints. Add them manually from documented requirements.
Does Draft 2020-12 guarantee format validation?
No. Format can be annotation-only depending on vocabulary and validator configuration. Verify the exact implementation you deploy.

Developer Tools guides

View all