JSON Data
JSON Schema
Draft-07Validation Results
Paste JSON and a Schema above, then click Validate.
Paste JSON and a Schema above, then click Validate.
JSON Schema Validator validates a JSON document against a JSON Schema definition. Paste your schema in the left panel and the JSON data in the right panel, then click Validate to check conformance. Errors include the path (e.g., /user/email), the constraint that failed (minLength, format, required), and a human-readable message. Supports JSON Schema drafts 4, 6, 7, 2019-09, and 2020-12.
JSON Schema is a vocabulary for annotating and validating JSON documents. A schema describes: required properties, property types (string, number, boolean, array, object, null), constraints (minLength, maxLength, pattern, minimum, maximum, enum), array item schemas, and composition keywords (allOf, anyOf, oneOf, not, if/then/else). JSON Schema is used to validate API request and response bodies, configuration files, and database documents.
JSON Schema is used in: OpenAPI specs (all schemas are JSON Schema), VS Code settings and extensions (IDE provides autocomplete and validation from .json schemas), MongoDB JSON Schema validation, Terraform variable type definitions, and GitHub Actions workflow files. The ajv library (JavaScript) is the most widely-used JSON Schema validator with near-complete spec support. JSON Schema's $ref supports both in-document references and external schema files via URLs.
Required field missing
Result: Schema: {required:['email']} / Data: {name:'Alice'} β Error: /email is required
Type mismatch
Result: Schema: {age: {type:'integer'}} / Data: {age:'thirty'} β Error: /age must be integer
Format validation
Result: Schema: {email:{format:'email'}} / Data: {email:'not-an-email'} β Error: /email must match format 'email'
What is the difference between JSON Schema draft-07 and draft 2020-12?
JSON Schema has evolved through several versions. Key changes from draft-07 to 2020-12: $vocabulary (2019-09) lets you declare which JSON Schema features your schema uses. unevaluatedProperties / unevaluatedItems (2019-09) allows you to validate properties not matched by other keywords. prefixItems (2020-12) replaced items for tuple validation; items now handles additional items. $dynamicRef / $dynamicAnchor (2020-12) enable extensible recursive schemas. OpenAPI 3.1 adopted draft 2020-12. Many validators still only support draft-07 β check compatibility before using new keywords.
How do I validate API request bodies with JSON Schema?
For Express.js: use ajv + express-json-validator-middleware: schema applied per-route as middleware. For FastAPI (Python): Pydantic models are automatically validated against request body JSON β define a class with type annotations. For Go: use gojsonschema or validate via your framework's binding. OpenAPI frameworks (NestJS with @nestjs/swagger, Hono, tRPC) generate schemas from TypeScript types automatically. Best practice: validate early at the API boundary, return 400 with specific error messages pointing to the invalid field and constraint violated.
What is the difference between allOf, anyOf, and oneOf in JSON Schema?
allOf: the data must be valid against ALL subschemas β used to combine schema fragments (composition/mixin). anyOf: the data must be valid against AT LEAST ONE subschema β more permissive. oneOf: the data must be valid against EXACTLY ONE subschema β for mutually exclusive types. Example: input can be a string OR a number (not both) β oneOf: [{type:'string'}, {type:'number'}]. When using if/then/else, this is often cleaner than oneOf for conditional validation. allOf is the most common β used in OpenAPI to extend base schemas.
How does the if/then/else keyword work in JSON Schema?
if/then/else enables conditional validation: if the data matches the if schema, it must also match the then schema; otherwise it must match the else schema. Example: validate payment objects differently based on type: if: {properties:{type:{const:'credit_card'}}}, then: {required:['card_number','cvv']}, else: {required:['bank_account','routing_number']}. This avoids having to duplicate common fields across oneOf branches. The if keyword doesn't fail validation by itself β only then or else can fail.
How do I use $ref to create reusable schemas?
$ref references another schema by its URI or JSON Pointer. In-document: {$ref: '#/$defs/Address'} β the # means root, then navigate to $defs.Address. The $defs keyword (2020-12) or definitions (draft-07) is the conventional location for reusable schemas. Example: {$defs: {Address: {type:'object', properties:{street:{type:'string'}, city:{type:'string'}}}}, properties:{home:{$ref:'#/$defs/Address'}, work:{$ref:'#/$defs/Address'}}}. External: {$ref: 'https://example.com/schemas/address.json'}. ajv supports HTTP resolution of external refs with the ajv-formats and ajv-uri-resolver plugins.