JSON Schema is the dominant standard for describing the shape of JSON data. Once you write a schema, you can validate any document against it — catching missing fields, wrong types, and bad values before they cause runtime bugs. Here's how to do it in three popular environments, plus an online tool that needs zero setup.
What schema validation actually does
A JSON Schema is itself a JSON document. It describes the structure your data should follow — required properties, value types, allowed enums, numeric ranges, string patterns, array constraints. A validator reads both the schema and your data and reports every mismatch.
Schemas pay off most in three places: API request validation (reject bad payloads at the edge, with helpful error messages), configuration files (catch typos before a service boots), and contract testing between teams (the schema is the source of truth both sides build to).
Method 1: validate online (zero setup)
The fastest way is our JSON Schema Validator. Paste your schema on the left, your document on the right, click Validate. You get the list of errors with JSON Pointers (/items/0/email) pointing to each problem location. Good for ad-hoc testing, debugging payloads, or learning how schemas behave.
Method 2: validate in JavaScript with Ajv
Ajv is the de facto standard JSON Schema validator for Node.js and browsers. It's fast (compiles schemas to optimized validator functions) and supports drafts 04, 06, 07, 2019-09, and 2020-12.
npm install ajv ajv-formats
const Ajv = require('ajv');
const addFormats = require('ajv-formats');
const ajv = new Ajv({ allErrors: true });
addFormats(ajv); // adds "email", "date", "uri", etc.
const schema = {
type: 'object',
required: ['id', 'email'],
properties: {
id: { type: 'integer', minimum: 1 },
email: { type: 'string', format: 'email' },
role: { type: 'string', enum: ['admin', 'user', 'guest'] }
},
additionalProperties: false
};
const validate = ajv.compile(schema);
const data = { id: 1, email: 'not-an-email', role: 'admin' };
if (!validate(data)) {
console.log(validate.errors);
}
Two flags matter most. allErrors: true tells Ajv to report every problem (default is to stop at the first); use it during development, turn it off in hot paths. strict: true rejects schemas with unknown keywords — set it when you want to catch typos in your schema itself.
Method 3: validate in Python with jsonschema
pip install jsonschema
from jsonschema import Draft202012Validator
schema = {
"type": "object",
"required": ["id", "email"],
"properties": {
"id": {"type": "integer", "minimum": 1},
"email": {"type": "string", "format": "email"},
"role": {"type": "string", "enum": ["admin", "user", "guest"]}
}
}
validator = Draft202012Validator(schema)
errors = sorted(validator.iter_errors(data), key=lambda e: e.path)
for e in errors:
print(f"{list(e.path)}: {e.message}")
Pin the draft explicitly (Draft202012Validator, Draft7Validator, etc.). Don't rely on autodetection — it's a subtle source of bugs when schemas mix idioms from different drafts.
Method 4: validate in Go
The santhosh-tekuri/jsonschema library is the standard choice in Go — fast, supports all drafts, and produces structured errors:
import "github.com/santhosh-tekuri/jsonschema/v5"
compiler := jsonschema.NewCompiler()
schema, _ := compiler.Compile("schema.json")
if err := schema.Validate(data); err != nil {
// *jsonschema.ValidationError has BasicOutput() for JSON-Schema-format errors
fmt.Println(err)
}
Common pitfalls
Forgetting additionalProperties: false. By default, JSON Schema allows extra properties. If you want a strict shape, set this. Otherwise typos like emial won't be flagged.
Confusing required with non-null. A property listed in required must exist; it can still be null unless you also forbid that with "type": ["string"] instead of ["string", "null"].
Format keywords are advisory by default. In some validators, "format": "email" is informational only — you have to enable format assertions. Ajv requires ajv-formats; jsonschema needs format_checker=FormatChecker().
Wrap-up
Validation only works if it runs. Wire your validator into the request pipeline (Express middleware, FastAPI dependency, gRPC interceptor) so every payload is checked before your business logic sees it. The five minutes you spend on the schema saves hours of debugging downstream.