Common JSON Schema Validator Errors and How to Fix Them
JSON Schema validation failures can be frustrating, especially when error messages are cryptic. Here are the most common validation errors and exactly how to fix each one.
1. "Data Does Not Match Any Schema in 'anyOf'"
Problem: Your data doesn't match any of the schemas listed in anyOf.
Cause: anyOf requires data to match at least one sub-schema. The data either matches none or matches in conflicting ways.
Solution: Check each sub-schema individually. Common fixes:
- Add the missing required property
- Fix a type mismatch
- If
anyOfshould beoneOf, change the keyword
{
"anyOf": [
{ "properties": { "type": { "const": "A" } } },
{ "properties": { "type": { "const": "B" } } }
]
}
2. "Additional Properties Not Allowed"
Problem: Your data contains properties not defined in the schema.
Cause: "additionalProperties": false explicitly blocks extra fields.
Solution:
- Remove unexpected properties
- Add them to the schema
- Change
additionalPropertiestotrue
"additionalProperties": false
// Data with extra field → error
{ "name": "Alice", "email": "a@a.com", "phone": "555-0123" }
3. "Type Should Be 'integer' but Got 'string'"
Problem: A field's value type doesn't match the schema definition.
Cause: Common type mismatches:
- Numeric IDs sent as strings:
"42"instead of42 - Boolean flags as strings:
"true"instead oftrue - Arrays where objects are expected
Solution: Convert values or update the schema type:
"id": { "type": ["integer", "string"] }
4. "String Does Not Match Pattern"
Problem: A string field fails the regex pattern validation.
Solution: Check your value against the pattern. Common issues:
- Missing required prefixes (e.g.,
+for phone numbers) - Incorrect character casing
- Missing delimiters (e.g., hyphens in IDs)
5. "Array Item Does Not Match Schema"
Problem: One or more items in an array fail the schema.
Solution: Debug by:
- Testing each array item individually
- Using
containsinstead ofitemsif only some items need to match - Checking for mixed types in a homogeneous array
"items": { "type": "string" }
// ["apple", "banana", 42, "date"] → item at index 2 fails
6. "Minimum Value Not Met"
Problem: A numeric value is below the defined minimum threshold.
Common scenarios: Minimum of 1 but value is 0 or negative; age fields with negative values.
7. "Required Property Missing"
Problem: A field in the required array is absent from the data.
Solution: Add the missing field, or if it should be optional, remove it from required:
"required": ["name", "email"]
8. "Format Validation Failed"
Problem: A string fails format validation (email, URI, date-time).
Common issues:
-
email: Missing
@, spaces in address -
uri: Missing protocol (
https://) - date-time: Wrong timezone format
- ipv4: Octet values over 255
Prevention Tips
- Build your schema incrementally — validate after each new constraint
- Use a JSON formatter before validation to catch syntax errors first
- Test your schema with both valid and invalid data samples
- Keep error messages descriptive for downstream users
- Document format requirements in API documentation
Summary
Most JSON Schema validation errors fall into predictable categories: type mismatches, missing required fields, unexpected additional properties, and format violations. Understanding each error type helps you resolve failures quickly and prevent them through better schema design.
Check out xingdian.net's JSON Schema Validator for free online processing.
Top comments (0)