How to generate a JSON Schema
- Paste a representative JSON example. Arrays with several items give the best results, because their items are merged into one schema.
- Choose the schema version (draft 2020-12 or draft-07) and whether properties should be required, formats detected and extra properties disallowed.
- Copy or download the schema, then refine it by hand – for example add descriptions, enums or minimum and maximum values.
What the generator infers
| JSON example | Schema |
|---|---|
"ada@example.com" | {"type": "string", "format": "email"} |
"2026-05-01T10:00:00Z" | format date-time (also date, time, uri, uuid, ipv4) |
42 / 4.5 | "integer" / "number" |
| a key present in every object | listed in required |
| a key missing in some array items | optional (not in required) |
[1, "a", null] | "items": {"type": ["string", "integer", "null"]} |
| objects mixed with plain values | anyOf with one schema per kind |
What is JSON Schema?
JSON Schema is a vocabulary for describing and validating the structure of JSON data: which properties exist, what type each one has, which are required and which values are allowed. It is used for API contracts in OpenAPI, configuration files, form generation and validating the structured output of AI models. The current version is 2020-12; draft-07 is still supported by many older tools. The specification is published at json-schema.org.
Refining the generated schema
- Add
titleanddescriptionto document what each field means. - Restrict values with
enum,minimum,maximum,maxLengthorpattern. - Tick Disallow extra properties (
additionalProperties: false) to reject unknown keys. - Validate data with Ajv in JavaScript or the
jsonschemapackage in Python.
Frequently asked questions
Which JSON Schema version should I use?
Use draft 2020-12 for new projects – it is the current version and the basis of OpenAPI 3.1. Choose draft-07 if your validator or tooling does not support 2020-12 yet.
Why are all my properties required?
With a single example object every property is present, so all of them are marked as required. Use an array with several varied examples, or switch off Mark properties as required.
Can the generator detect enums or ranges?
No. One example cannot show which values are allowed in general, so enums, minimum and maximum values and patterns have to be added by hand.
How do I validate JSON against the schema?
Use a validator library such as Ajv for JavaScript or jsonschema for Python. Many code editors also validate a JSON file against the schema referenced in its $schema property.