Free tool
JSON Schema generator and validator
Paste sample JSON to generate a JSON Schema (draft 2020-12 or draft-07), with required fields, nullable types and string formats inferred from all your samples. Then switch to validate and check any JSON against a schema, with every error and its path.
Free · no sign-up · runs in your browser, nothing is uploaded
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string",
"format": "email"
},
"name": {
"type": "string"
},
"signedUpAt": {
"type": "string",
"format": "date-time"
},
"plan": {
"type": "string"
},
"seats": {
"type": "integer"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"address": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"postcode": {
"type": [
"string",
"null"
]
}
},
"required": [
"city",
"postcode"
]
},
"referrer": {
"type": "string",
"format": "uri"
}
},
"required": [
"id",
"email",
"name",
"signedUpAt",
"plan",
"seats",
"tags",
"address"
]
}
}How the schema is generated
Each value in the sample maps to a schema keyword. With several samples, the generator merges them and only keeps what holds for all of them.
| In the samples | In the schema | Note |
|---|---|---|
| "seats": 5 | "type": "integer" | Whole numbers in every sample; any decimal makes it "number". |
| "name": "Ada" | "type": "string" | |
| "postcode": null in one sample | "type": ["string", "null"] | Present but sometimes null. |
| "referrer" in only some samples | left out of "required" | Keys present in every sample are required. |
| "email": "ada@example.com" | "format": "email" | Only when every sample matches: date-time, date, time, email, uri, uuid, ipv4. |
| "tags": [] | "items": {} | An empty array allows any items. |
| [1, "x", { ... }] | "anyOf": [...] | Mixed types that need their own keywords. |
No extra properties adds "additionalProperties": false to every object, so unknown keys fail validation. Add examples copies up to three sample values into examples, which documentation tools show. The schema is a starting point: add enum, minimum, maxLength or pattern where you know the rules, because a sample cannot tell the generator what values are allowed.
Draft 2020-12 vs draft-07
Most simple schemas work the same in both. These are the changes you are likely to meet:
| What | Draft-07 | Draft 2020-12 |
|---|---|---|
| $schema URI | http://json-schema.org/draft-07/schema# | https://json-schema.org/draft/2020-12/schema |
| Tuple (fixed positions) | "items": [ ... ] + "additionalItems" | "prefixItems": [ ... ] + "items" |
| Reusable definitions | "definitions" | "$defs" (since 2019-09) |
| Key depends on key | "dependencies" | "dependentRequired" / "dependentSchemas" (since 2019-09) |
| Keywords next to $ref | ignored | applied too (since 2019-09) |
| format | validators may assert it | annotation unless asserted (since 2019-09) |
What the validator checks
The validator is written for this page and runs in your browser. It reports every failing rule, not only the first, each with the path of the value ($.users[0].email), its JSON Pointer and the schema path of the rule. It evaluates these keywords:
type · enum · const · minimum · maximum · exclusiveMinimum · exclusiveMaximum · multipleOf · minLength · maxLength · pattern · format · items · prefixItems · additionalItems · contains · minContains · maxContains · minItems · maxItems · uniqueItems · properties · patternProperties · additionalProperties · required · propertyNames · minProperties · maxProperties · dependentRequired · dependentSchemas · dependencies · allOf · anyOf · oneOf · not · if · then · else · $ref · $defs · definitions · $anchor
$ref works for local references (#/$defs/address, # and $anchor names), including recursive schemas. Remote references, unevaluatedProperties, unevaluatedItems and $dynamicRef are not evaluated; when a schema uses them, the result says so instead of passing silently. Unknown keywords (like OpenAPI's nullable) are listed too, since validators ignore them.
Validate JSON Schema in code
JavaScript (Ajv). The default Ajv class is for draft-07; import ajv/dist/2020 for 2020-12. Format checks need ajv-formats, and allErrors collects every error instead of stopping at the first.
import Ajv2020 from 'ajv/dist/2020';
import addFormats from 'ajv-formats';
const ajv = new Ajv2020({ allErrors: true });
addFormats(ajv);
const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);Python (jsonschema).
from jsonschema import Draft202012Validator
validator = Draft202012Validator(schema, format_checker=Draft202012Validator.FORMAT_CHECKER)
for error in validator.iter_errors(data):
print(list(error.absolute_path), error.message)Prefer TypeScript types to a schema? The JSON to TypeScript converter writes interfaces or Zod schemas from the same sample.
Gotchas
- Objects accept unknown keys by default. Without
additionalProperties: false, a typo like"emial"passes. Add it where you want strict input. - Use the right $schema. A 2020-12 schema with
prefixItemsrun through a draft-07 validator is not checked as a tuple, because draft-07 does not know that keyword. - Integer is a value check. In JSON Schema,
1.0is a valid integer, since the number has no fractional part. - pattern is not anchored.
"pattern": "\\d+"matches"abc1". Write^\\d+$to match the whole string.
Fix broken JSON first with the JSON formatter, or query parts of it with the JSONPath tester. More tools for building and testing APIs are in API tools on DevHunt.
More free developer tools
FAQ
What is JSON Schema?+
JSON Schema is a JSON document that describes what other JSON must look like: which properties exist, their types, which are required, string formats, number ranges and so on. Validators use it to check data, OpenAPI uses it to describe request and response bodies, and editors use it for autocompletion in config files.
How do I generate a JSON Schema from JSON?+
Paste a sample into the box above and the schema appears as you type. Paste an array of objects or JSON Lines and turn on "Top-level array = samples of one object" to merge many samples: a property that is missing from some of them is left out of "required", and values that are sometimes null get ["string", "null"].
How do I validate JSON against a schema?+
Switch to "Validate JSON against a schema", paste the schema on the left and the data on the right. Every error is listed with the path of the bad value (like $.users[0].email) and the schema rule that failed. In code, use Ajv in JavaScript or the jsonschema package in Python.
Which JSON Schema version should I use?+
Use draft 2020-12 for new schemas; it is the current version and OpenAPI 3.1 is aligned with it. Pick draft-07 if a tool you depend on only supports the older drafts. The generator writes the matching $schema URI so validators know which rules apply.
Does "format": "email" make validation fail for bad emails?+
Not by default. Since draft 2019-09 the spec treats format as an annotation unless the validator is told to assert it. Ajv needs the ajv-formats plugin, and python-jsonschema needs a format checker. This tool checks formats by default; untick "Check format" to match a validator that ignores them.
What is the difference between required and nullable?+
"required" lists the properties that must be present. A required property can still be null if its type allows it, for example "type": ["string", "null"]. An optional property may be missing entirely, but when present it must match its schema.
Is my JSON uploaded?+
No. Generating and validating both run in your browser and nothing is sent to a server. Short inputs are kept in the page URL so you can share a result, so do not share links that contain private data.
Sources: JSON Schema 2020-12 release notes · JSON Schema 2019-09 release notes · JSON Schema validation spec (2020-12) · Understanding JSON Schema · Ajv: JSON Schema drafts · ajv-formats · python-jsonschema. Checked 2026-10-29.