JSON Schema Validation: A Short Practical Guide
JSON Schema is itself a JSON document that describes the shape another piece of JSON must have — which fields are required, what type each value should be, and what constraints apply. It answers a different question than a syntax check: not "is this valid JSON?" but "does this JSON match the rules I expect?"
A minimal example
This schema requires an object with a non-empty name and a non-negative integer age; email is optional but must look like an email address if present.
Schema
{
"type": "object",
"required": ["name", "age"],
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0 },
"email": { "type": "string", "format": "email" }
}
}Valid instance
{"name": "Ann", "age": 30}Invalid instance
{"name": "", "age": -1}The invalid instance fails on two keywords at once: minLength rejects the empty name, and minimum rejects the negative age — both are structurally valid JSON, so a syntax-only check would pass them without complaint.
Keywords you'll use most
type— restricts a value tostring,number,integer,boolean,object,array, ornullrequired— an array of property names that must be present on an objectproperties— the sub-schema for each named field on an objectitems— the sub-schema every element of an array must satisfyenum— restricts a value to a fixed list of allowed valuesminimum/maximum,minLength/maxLength,pattern— range and format constraints on numbers and strings
Where this is actually used
JSON Schema backs request/response validation in OpenAPI-described APIs, config-file validation in many CLI tools, and auto-generated forms. It needs a schema-aware library to run — for example ajv in JavaScript/Node or jsonschemain Python — since, unlike a plain syntax check, it can't evaluate a JSON document on its own without the schema alongside it.
Before validating structure, your JSON has to parse at all — see common JSON syntax errors if a document is failing to parse, or use the JSON validator to check syntax with line/column error reporting.
JSON Schema FAQ
- Is JSON Schema the same as this site's JSON validator?
- No. The JSON validator only checks that text is syntactically valid JSON. JSON Schema checks structure — required fields, types, ranges — against a schema you define, which is a separate step after syntax is already valid.
- What does "required" do in a schema?
- It lists the property names that must be present on an object for it to pass validation. A missing required property fails validation even if every other field is correctly typed.
- Can a schema validate an array of objects?
- Yes. The `items` keyword applies a schema to every element of an array, so you can require that each object in a list has the same shape.
- Where do I actually run JSON Schema validation?
- With a schema-aware validator library, since it needs both your JSON and a schema — for example ajv in JavaScript/Node, or jsonschema in Python. This site's tools currently check syntax only, not schemas.