What is JSON Schema Validation?
JSON Schema validation is the process of checking whether a JSON document conforms to a set of structural and value constraints defined in a JSON Schema. The schema itself is a JSON document that describes the expected shape of your data: which properties are required, what types they must be, the allowed ranges for numbers, string patterns, array lengths, and more. The JSON Schema specification is maintained at json-schema.org and published as a series of IETF drafts, Draft 7 and Draft 2020-12 are the most widely adopted.
Where plain JSON validation only checks syntax (are the brackets matched? are strings quoted?), schema validation goes further. It answers questions like: does the response from this API contain an "id" field that is always an integer? Is the "status" field one of three allowed values? Are nested objects shaped correctly? This kind of structural verification catches bugs that syntax checks miss entirely, because syntactically valid JSON can still be semantically wrong for your application.
JSON Schema is used in OpenAPI/Swagger definitions, configuration file validation, form validation, database document constraints, and automated testing. Tools like Ajv (JavaScript), jsonschema (Python), and check-jsonschema (CLI) implement the specification so you can validate data programmatically. This online validator lets you paste both a schema and a data document to check conformance instantly, without installing any library.
Why Use an Online JSON Schema Validator?
Writing schemas and debugging validation errors by hand is slow. An online JSON Schema validator gives you instant feedback on whether your data matches your schema, with clear error messages pointing to the exact property that failed.
JSON Schema Validation Use Cases
JSON Schema Keywords Reference
A JSON Schema is built from keywords that each impose a constraint on the validated data. The table below lists the most commonly used keywords in Draft 7 and later. Every keyword can be combined with others in the same schema object.
| Keyword | Purpose | Example |
|---|---|---|
| type | Restricts the data type | "type": "string" |
| properties | Defines expected object keys and their schemas | "properties": { "name": { "type": "string" } } |
| required | Lists mandatory properties | "required": ["id", "name"] |
| items | Schema for array elements | "items": { "type": "number" } |
| enum | Restricts value to a fixed set | "enum": ["active", "inactive"] |
| pattern | Regex constraint on strings | "pattern": "^[A-Z]{2}\\d{4}$" |
| minimum / maximum | Numeric range bounds | "minimum": 0, "maximum": 100 |
| minLength / maxLength | String length bounds | "minLength": 1, "maxLength": 255 |
| $ref | Reuses another schema by URI | "$ref": "#/$defs/address" |
| additionalProperties | Controls extra keys in objects | "additionalProperties": false |
| anyOf / oneOf / allOf | Combines multiple schemas logically | "anyOf": [{ "type": "string" }, { "type": "null" }] |
| if / then / else | Conditional schema application | "if": { "properties": { "type": { "const": "email" } } } |
JSON Schema Draft Comparison: Draft 7 vs 2019-09 vs 2020-12
JSON Schema has gone through several draft versions. Draft 7 (published 2018) is the most widely supported in tooling. Draft 2019-09 introduced $defs (replacing definitions), unevaluatedProperties, and $recursiveRef. Draft 2020-12 (the latest stable release) replaced $recursiveRef with $dynamicRef and introduced prefixItems for tuple validation. When choosing a draft, check that your validation library supports it. Ajv supports all three drafts. Python's jsonschema library supports up to 2020-12 since version 4.0.
| Feature | Draft 7 | Draft 2019-09 | Draft 2020-12 |
|---|---|---|---|
| $schema URI | draft-07/schema# | 2019-09/schema | 2020-12/schema |
| if / then / else | Yes | Yes | Yes |
| $defs (definitions) | definitions | $defs | $defs |
| $ref alongside keys | No (sibling ignored) | Yes | Yes |
| $dynamicRef | No | No ($recursiveRef) | Yes |
| prefixItems | No (use items array) | No (use items array) | Yes |
| unevaluatedProperties | No | Yes | Yes |
| $vocabulary | No | Yes | Yes |
Code Examples
These examples show how to validate JSON against a schema programmatically. Each uses a well-maintained library for its language ecosystem.
import Ajv from 'ajv';
const ajv = new Ajv();
const schema = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1 },
age: { type: 'integer', minimum: 0 },
email: { type: 'string', format: 'email' }
},
required: ['name', 'email'],
additionalProperties: false
};
const data = { name: 'Alice', age: 30, email: 'alice@example.com' };
const validate = ajv.compile(schema);
const valid = validate(data);
console.log(valid); // → true
console.log(validate.errors); // → null
// Invalid data — missing required "email"
validate({ name: 'Bob', age: 25 });
console.log(validate.errors);
// → [{ instancePath: '', keyword: 'required', params: { missingProperty: 'email' } }]from jsonschema import validate, ValidationError
schema = {
"type": "object",
"properties": {
"name": {"type": "string", "minLength": 1},
"age": {"type": "integer", "minimum": 0},
"tags": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": True
}
},
"required": ["name"]
}
# Valid data
validate(instance={"name": "Alice", "age": 30, "tags": ["admin"]}, schema=schema)
# → No exception raised
# Invalid data — wrong type for "age"
try:
validate(instance={"name": "Alice", "age": "thirty"}, schema=schema)
except ValidationError as e:
print(e.message)
# → 'thirty' is not of type 'integer'
print(e.json_path)
# → $.agepackage main
import (
"fmt"
"strings"
"github.com/santhosh-tekuri/jsonschema/v5"
)
func main() {
schemaJSON := `{
"type": "object",
"properties": {
"id": { "type": "integer" },
"status": { "enum": ["active", "inactive"] }
},
"required": ["id", "status"]
}`
compiler := jsonschema.NewCompiler()
compiler.AddResource("schema.json", strings.NewReader(schemaJSON))
schema, _ := compiler.Compile("schema.json")
// Valid data
data := map[string]interface{}{"id": 1, "status": "active"}
err := schema.Validate(data)
fmt.Println(err) // → <nil>
// Invalid — missing "status"
bad := map[string]interface{}{"id": 2}
err = schema.Validate(bad)
fmt.Println(err) // → validation failed: missing properties: 'status'
}# Install via pip pip install check-jsonschema # Validate a file against a schema check-jsonschema --schemafile schema.json data.json # → ok -- validation done # Validate against a remote schema (e.g., GitHub Actions workflow) check-jsonschema --builtin-schema vendor.github-workflows my-workflow.yml # Validate multiple files at once check-jsonschema --schemafile schema.json file1.json file2.json file3.json