Validating JSON with a schema
JSON Schema is a vocabulary for describing JSON documents: which properties exist, their types, allowed values, and nesting. Validation compares a parsed JSON instance against such a schema—not against “looks like JSON” syntax rules.
On this page the left editor holds the instance (payload), the right editor holds the schema JSON. Syntax must be valid on both sides before structural checks run; schema-side errors and match results appear in the right footer.
JSON Schema — background
Instance document vs schema document
The instance is your data: API body, config, message. The schema is another JSON document that uses keywords such as type, properties, required, items, enum, and format to constrain that data. Validators (here: Ajv) compile the schema, then test the instance keyword by keyword.
Common keywords you will see
type restricts values (object, array, string, number, integer, boolean, null). properties names fields on objects; required lists mandatory keys. items describes array elements. enum lists allowed literals; pattern applies a regex to strings. format adds semantic checks (email, date-time, uri) when both schema and validator support them.
Error paths (JSON Pointer)
Failures reference locations like /contact or /items/0/price. That is JSON Pointer syntax: /contact is a root property; /items/0 is the first array element. Pointers map directly to positions in the instance JSON, which is why they are used in APIs and OpenAPI examples.
Drafts: 07, 2019-09, 2020-12
The $schema URL declares which specification version the schema follows. Draft-07 is widely deployed; 2019-09 and 2020-12 add keywords such as unevaluatedProperties and adjusted $ref behavior. Validators must use the matching dialect—this page reads $schema and rejects unknown draft URLs.
Where validation fits
Contract before integration
OpenAPI and AsyncAPI often embed JSON Schema for request bodies. Checking a sample payload against that schema catches wrong types or missing required fields before you depend on a remote 400 response.
Stricter vs permissive schemas
additionalProperties: false rejects unknown keys; omitting it (draft-07 default) allows extras unless you tighten with unevaluatedProperties in newer drafts. Validation outcome reflects what your schema actually says—not an implicit “strict JSON” rule.