Schema Validation
JSON Schema validation lets you verify that your data conforms to a defined structure. Paste or write a JSON Schema, click Validate, and JSONFiddle tells you exactly which fields are wrong and why.
JSONFiddle uses AJV (Another JSON Validator), the fastest and most standards-compliant JSON Schema validator for JavaScript.
Click the Validate Schema button (shield icon) in the bottom bar to open the validation modal.
Screenshot: The bottom bar with the Validate Schema button visible.
Prerequisites
- Valid JSON data in the editor.
- A JSON Schema to validate against.
How to Use
- Paste your JSON data into the editor.
- Click the Validate Schema button in the bottom bar.
- Paste or type your JSON Schema in the schema editor.
- Click Validate.
- Results appear below:
- Green checkmark: Data is valid.
- Red errors: Each error lists the path, the expected constraint, and what was found.
Screenshot: The bottom bar showing the Validate Schema button.
Attaching a Schema
When you validate with a schema, it becomes attached to the current tab. The button shows "Validate Schema (attached)" and uses a filled style. The next time you open the modal, the attached schema is pre-loaded.
Supported JSON Schema Versions
| Draft | Supported | Notes |
|---|---|---|
| Draft-04 | Yes | Widely used legacy version. |
| Draft-06 | Yes | Added const, contains, propertyNames. |
| Draft-07 | Yes | Added if/then/else, readOnly, writeOnly. |
| 2019-09 | Yes | Added $defs, dependentRequired, unevaluatedProperties. |
| 2020-12 | Yes | Latest stable version. Added prefixItems. |
Tip: Choose 2020-12 for new schemas.
Understanding Validation Errors
Each error contains:
| Field | Description | Example |
|---|---|---|
| Path | The JSON path to the invalid value. | /users/0/email |
| Message | What the schema expected. | must match format "email" |
| Schema keyword | The JSON Schema keyword that failed. | format |
Common Error Messages
| Error | Meaning | Fix |
|---|---|---|
must be string | Expected a string, got another type. | Check the value type. |
must be number | Expected a number, got another type. | Ensure the value is numeric (not quoted). |
must have required property 'name' | A required field is missing. | Add the missing field. |
must NOT have additional properties | An extra field exists that the schema does not allow. | Remove the extra field or update the schema. |
must match format "email" | The string does not match the expected format. | Ensure the value is a valid email. |
must be >= 0 | The number is below the minimum. | Increase the value. |
must be <= 100 | The number is above the maximum. | Decrease the value. |
must NOT have fewer than 1 items | The array is empty but must have at least one item. | Add an item. |
must match pattern "^[a-z]+$" | The string does not match the regex pattern. | Fix the string. |
Example Schemas
User Object
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["id", "name", "email"],
"properties": {
"id": { "type": "integer", "minimum": 1 },
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0, "maximum": 150 },
"active": { "type": "boolean" },
"roles": {
"type": "array",
"items": { "type": "string", "enum": ["admin", "editor", "viewer"] },
"minItems": 1,
"uniqueItems": true
}
},
"additionalProperties": false
}
API Response Envelope
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["status", "data"],
"properties": {
"status": { "type": "string", "enum": ["success", "error"] },
"data": { "type": ["object", "array", "null"] },
"error": {
"type": "object",
"properties": {
"code": { "type": "string" },
"message": { "type": "string" }
},
"required": ["code", "message"]
},
"meta": {
"type": "object",
"properties": {
"page": { "type": "integer", "minimum": 1 },
"total": { "type": "integer", "minimum": 0 },
"per_page": { "type": "integer", "minimum": 1, "maximum": 100 }
}
}
}
}
Configuration File
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["server"],
"properties": {
"server": {
"type": "object",
"required": ["host", "port"],
"properties": {
"host": { "type": "string" },
"port": { "type": "integer", "minimum": 1, "maximum": 65535 },
"debug": { "type": "boolean", "default": false },
"cors_origins": {
"type": "array",
"items": { "type": "string", "format": "uri" }
}
}
},
"database": {
"type": "object",
"required": ["url"],
"properties": {
"url": { "type": "string", "format": "uri" },
"pool_size": { "type": "integer", "minimum": 1, "maximum": 100, "default": 10 }
}
}
}
}
Product Catalog
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": { "type": "string", "pattern": "^PROD-[0-9]{4}$" },
"name": { "type": "string", "minLength": 1, "maxLength": 200 },
"price": { "type": "number", "minimum": 0, "exclusiveMinimum": 0 },
"category": { "type": "string", "enum": ["electronics", "clothing", "food", "other"] },
"tags": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
"dimensions": {
"type": "object",
"properties": {
"width": { "type": "number", "minimum": 0 },
"height": { "type": "number", "minimum": 0 },
"depth": { "type": "number", "minimum": 0 }
}
}
}
},
"minItems": 1
}
Screenshot: The bottom bar showing the Validate Schema button ready to use.
Troubleshooting
"The Validate Schema button is disabled"
Your JSON content is invalid. Fix the syntax errors first (check the "Invalid" badge).
"Validation passes but I expected errors"
Common issues:
- Missing
"required"array (fields are optional by default). "additionalProperties"is not set tofalse(extra fields are allowed by default).- The schema
"type"does not match the root structure.
"The schema itself has an error"
The modal validates the schema before using it. If the schema JSON is invalid, you see an error. Fix the schema's JSON syntax.
"Format validations are not working"
AJV supports format validation for common formats (email, uri, date, date-time, ipv4, ipv6, etc.). If a format is not recognized, use "pattern" with a regex as a fallback.
FAQ
Q: Can I use $ref to reference external schemas?
A: Local $ref references within the same schema document are supported. External URL references are not fetched.
Q: Can I validate YAML or XML data? A: Yes. JSONFiddle reads YAML and XML as structured data before validating it against the schema.
Q: Is the validation done client-side? A: Yes. AJV runs entirely in the browser. Your data and schema never leave your machine.
Q: Can I save schemas for reuse? A: Schemas are attached to the current tab and persist in session storage. They survive page refreshes but not browser tab closures.
Q: Can I auto-generate a schema from my data? A: Not currently. Consider using an online tool to generate an initial schema, then validate it in JSONFiddle.
Related Guides
- Bottom Bar -- where the Validate Schema button lives.
- Type Generation -- generate code types instead of validating against a schema.
- Getting Started -- overview of the bottom bar tools.
- Format Conversion -- validate after converting between formats.