Generate a JSON Schema from an example
Writing a schema by hand is slow. Paste a representative JSON sample and get a draft 2020-12 JSON Schema with types, required properties and string formats, ready to refine and use for validation, documentation or OpenAPI.
How to use it
- Paste a JSON sample into the Input panel. Arrays with several items give the best results.
- The schema appears in the Output panel.
- Copy it or download it as
Root.schema.json, then add descriptions, enums or limits as needed.
What is inferred
typefor every value, usingintegerornumberas appropriate.required: keys present in every object of an array.- Nullable values as
["string", "null"]. formatfor strings that are all emails, dates, date-times, URIs or UUIDs.
Validating data with the schema
Use any JSON Schema validator, for example Ajv in JavaScript:
import Ajv2020 from "ajv/dist/2020";
import addFormats from "ajv-formats";
const ajv = new Ajv2020();
addFormats(ajv);
const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);
More JSON tools
All tools are free and run privately in your browser.
JSON Schema Generator FAQ
Which JSON Schema version is generated?
Draft 2020-12, the current version, declared with the $schema keyword. It also works with most draft-07 validators.
How are required properties decided?
A key is required if it appears in every object of the sample. Keys that are missing from some items are left optional.
Is my data uploaded to a server?
No. The JSON Schema Generator runs entirely in your browser using JavaScript. Your data is never uploaded, logged or stored, and the tool keeps working offline after your first visit.