Cookie preferences
We use cookies for analytics. Privacy Policy You can accept or decline non-essential tracking.
Practical guide to json schema validation: formulas, workflow, implementation pitfalls, and a direct execution playbook with JSON Formatter.
Go to tool
Validation, formatting and syntax highlighting for JSON.
JSON Schema is a contract that defines the structure, types, and constraints of a JSON document. Validate payloads before sending them to an API, and you catch errors client-side instead of debugging cryptic 400 responses.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
},
"role": {
"type": "string",
"enum": ["admin", "user", "viewer"]
}
},
"required": ["email", "role"]
}This schema enforces: email must be a valid email string, age must be an integer 0-150, role must be one of three values, and both email and role are required.
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
const ajv = new Ajv();
addFormats(ajv); // adds "email", "uri", "date-time", etc.
const schema = {
type: 'object',
properties: {
email: { type: 'string', format: 'email' },
role: { type: 'string', enum: ['admin', 'user', 'viewer'] }
},
required: ['email', 'role']
};
const validate = ajv.compile(schema);
const payload = { email: 'not-an-email', role: 'superadmin' };
if (!validate(payload)) {
console.error(validate.errors);
// [{keyword: 'format', message: 'must match format "email"'}, ...]
}from jsonschema import validate, ValidationError
schema = {
"type": "object",
"properties": {
"email": {"type": "string", "format": "email"},
"role": {"type": "string", "enum": ["admin", "user", "viewer"]}
},
"required": ["email", "role"]
}
try:
validate(instance={"email": "[email protected]"}, schema=schema)
except ValidationError as e:
print(e.message) # 'role' is a required propertyBefore testing any API call, paste your JSON payload into the JSON Formatter to validate syntax and prettify the structure. A single trailing comma or misquoted key will fail silently in many HTTP clients -- catch it visually first.
This article is reviewed by the Tools Hub editorial team for factual accuracy, practical relevance, and consistency with current product workflows.
Last reviewed:
Use the AI Assistant in JSON Formatter to quickly repair invalid API payloads, fix syntax errors, and improve schema readiness before integration.
A pre-release checklist for JSON payload quality covering AI-assisted validation, schema structure review, and integration handoff readiness.
Paste any code snippet into Code Explainer AI and get a structured, human-readable explanation of logic, patterns, and edge cases in seconds.
Use Code Converter AI to translate functions and modules between Python, JavaScript, Go, Rust, and TypeScript while preserving idiomatic patterns.