Skip to content
{ }JSON Formatter

JSON to JSON Schema

Generate a JSON Schema (draft 2020-12) from a sample — types, nested properties, required and array item schemas inferred. Then validate other documents against it.

Input
Output
Paste input and press Generate Schema.

A schema from an example

Writing a JSON Schema by hand is tedious; inferring one from a representative document is fast. Paste a JSON sample and this tool produces a draft 2020-12 schema: each value's type is detected (string, integer, number, boolean, null), nested objects get their own properties, and arrays get an items schema describing their elements.

required & nullable, inferred

A property is added to a required list when it appears in every record of the sample. When a value is sometimes null, its type becomes a union like ["string", "null"]. Feeding an array of similar objects gives the best result — the tool merges their shapes, so a field missing from one object is correctly treated as optional rather than required.

Then validate against it

Take the generated schema to the JSON Schema Validator to check other documents against it, or refine it by hand — add format, minLength, enum and descriptions where you know the rules. The inferred structure is the starting point; the constraints are yours to tighten.

Frequently asked questions

Which JSON Schema draft does it target?

Draft 2020-12 — the current version — declared via the $schema keyword. The output validates with modern validators including the one on this site, which supports 2020-12.

How is required determined?

A property is listed in required only when it is present in every object of the sample. That is why an array of examples gives better output than a single object: a field missing from one of them is correctly inferred as optional.

How are nullable and mixed values handled?

When a value is null in some records and typed in others, the type becomes a union such as ["string", "null"]. Genuinely mixed types (or a value that is only ever null with no other signal) fall back to a permissive empty schema {} that accepts anything.

Does it add formats, patterns or enums?

No — it infers structure and types, not constraints. Add format: "email", minLength, pattern, enum and descriptions yourself where you know the rules; the tedious type/required scaffolding is done for you.