Example
[
{
"id": 1,
"email": "ada@example.com",
"role": "admin",
"signedUpAt": "2026-01-05T10:00:00Z"
},
{
"id": 2,
"email": "grace@example.com",
"role": "editor",
"signedUpAt": "2026-02-11T08:30:00Z",
"nickname": null
}
]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string",
"format": "email"
},
"role": {
"type": "string"
},
"signedUpAt": {
"type": "string",
"format": "date-time"
},
"nickname": {
"type": "null"
}
},
"required": [
"id",
"email",
"role",
"signedUpAt"
]
}
}
nicknameonly appears in one object, so it isn’t inrequired.emailandsignedUpAtgotformat: emailandformat: date-time.rolelooks like a fixed set of values; consider adding"enum": ["admin", "editor"]by hand.
Validate data against the schema
Click Validate with it to open the schema and your JSON in the JSON Schema Validator, or validate in code:
// npm install ajv ajv-formats
import Ajv2020 from 'ajv/dist/2020';
import addFormats from 'ajv-formats';
const ajv = new Ajv2020({ allErrors: true });
addFormats(ajv); // without this, "format" is not checked
const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);
# pip install jsonschema
from jsonschema import Draft202012Validator
validator = Draft202012Validator(schema, format_checker=Draft202012Validator.FORMAT_CHECKER)
for error in validator.iter_errors(data):
print(error.json_path, error.message)
Where JSON Schema is used
- API validation: reject bad request bodies before they reach your code (Fastify uses it natively).
- OpenAPI: request and response models in OpenAPI 3.1 are JSON Schema 2020-12.
-
Editor autocomplete: add
"$schema": "./config.schema.json"to a JSON config file and VS Code validates it and suggests keys as you type. - LLM structured output: function calling and structured output APIs take a JSON Schema for the response.
Prefer types in code? Generate Zod schemas, Pydantic models or TypeScript interfaces from the same JSON.
Frequently asked questions
How do I generate a JSON Schema from JSON?
Paste a sample JSON document into the tool above. It infers a schema with the type of every value, a properties entry for every key, a required list of keys present in all samples, and formats such as email, uri, uuid and date-time. Use an array of several objects to get a more accurate result.
Which draft should I use?
Use 2020-12, the current version, unless a tool requires an older one. Draft 7 is still the most widely supported, for example in some IDEs and older validators, and OpenAPI 3.0 uses a variant of it. OpenAPI 3.1 is fully aligned with 2020-12.
How is “required” decided?
A key is required when it appears in every sample object. If you paste a single object, every key is required; paste an array of several representative objects and keys that are missing from some of them are left out of required.
Why does my validator ignore “format”?
Since draft 2019-09, format is an annotation by default: validators record it but don’t reject invalid values unless format checking is turned on. In Ajv, install ajv-formats and call addFormats(ajv). In Python’s jsonschema, pass a format_checker.
Is the generated schema complete?
It describes the structure of your sample, which is the tedious part. You will usually want to tighten it by hand: add enum for fixed values, minimum and maximum for numbers, minLength or pattern for strings, and descriptions for documentation.