How to Validate JSON Against a JSON Schema and Read the Errors
A practical guide to JSON Schema: drafts, the most used keywords, reading error paths, batch checks of exports and a first schema built from sample data.

A JSON Schema is a contract. It says which properties a document must have, what types they are and which values are allowed. APIs use it to reject bad requests, editors use it for autocomplete in configuration files, and data teams use it to catch broken records before they reach a warehouse. This guide covers the essentials and shows how to find out exactly why a document fails.
The keywords you will use most
typelimits a value to string, number, integer, boolean, object, array or null.requiredlists properties that must be present.propertiesgives a schema for each named property, andadditionalProperties: falseforbids anything else.enumandconstrestrict a value to a fixed list or one value.minimum,maximum,minLength,maxLengthandpatternset ranges and formats.itemsdescribes array elements;uniqueItemsforbids duplicates.$refreuses a definition, usually from$defs.anyOf,oneOf,allOf,notandif/then/elsecombine rules.
Drafts matter
JSON Schema has several published versions. Draft 7 is still very common, and 2020-12 is the current one. They differ in details: 2020-12 uses prefixItems for tuples where draft 7 used an array in items, and in draft 7 a $ref makes the validator ignore keywords next to it. The $schema line at the top tells a validator which rules to apply, so keep it in your schemas.
Reading an error
A useful error has three parts. The instance path, such as /address/country, says where in your data the problem is. The keyword, such as pattern, says which rule failed. The schema path, such as #/$defs/address/properties/country/pattern, says where that rule lives in the schema. With all three you can decide quickly whether the data or the schema is wrong.
Errors from anyOf and oneOf are the hardest to read, because the data failed several alternatives at once. A good validator reports the combination failure and the errors of the closest alternative.
Validating with the tool
The JSON Schema Validator runs in your browser.
- Paste the schema, or tap Sample to see a realistic one with
$defs,if/thenand formats. - Paste the data: one document, an array of records or JSON Lines.
- Leave the draft on automatic, or force one. Choose whether to validate the whole input or each item.
- Read the results. Every document shows a tick or the full list of errors with paths and keywords.
- Edit and watch the results update. Undo is there if an edit goes wrong.
- Download the errors as CSV for a ticket, or the full report as JSON.
Checking an export in one go
Batch mode is where a validator earns its keep. Paste a JSON array or a JSON Lines dump and each record is validated separately and labelled by its index or line number. The summary tells you how many records are invalid and how many errors there are in total, so you can tell at a glance whether one record is broken or the whole feed changed shape.
Starting a schema from data
Writing a schema from scratch is slow. Schema from data infers one from your sample: types, nested objects, array items, formats such as date or email, and the properties present in every record as required. Treat it as a first draft. Tighten it with enums, ranges and patterns that reflect real business rules, and decide deliberately whether extra properties are allowed.
Limits worth knowing
References to other files or URLs are not downloaded; copy those definitions into $defs. Format checks test syntax only, so a well-formed email address may still not exist. Specialised vocabularies and content keywords are not evaluated.
Summary
Keep $schema in every schema, read errors by instance path first, validate exports record by record, and grow a schema from real samples. A few minutes of validation saves hours of tracing a bad record through a pipeline.



