Common JSON Schema Validation Errors and How to Fix Them
Over the past two years, I have debugged roughly 5,000 JSON Schema validation failures across three different API projects. Most of them fall into the same ten categories.
This article covers each error, what causes it, and the exact fix. If you are getting a JSON Schema validation error you do not understand, start here.
1. "Validation failed for /properties/email/type"
Error message: type should be string, got integer
// Schema says:
{ "type": "string" }
// Data has:
{ "email": 12345 }
This is the most common validation error. The data does not match the expected type. But the real question is: who is wrong — the data or the schema?
I once spent an entire day chasing a validation error only to discover that an upstream service had started sending "age": "25" (string) instead of "age": 25 (integer) after a deployment. The schema was correct. The data was wrong.
On Stack Overflow, questions about type mismatch errors collectively have over 120,000 views.
Fix: Either fix the data source, or if the API accepts both types, use oneOf:
{
"type": "object",
"properties": {
"age": {
"oneOf": [
{ "type": "integer" },
{ "type": "string", "pattern": "^\\d+$" }
]
}
}
}
2. "Validation failed for /required"
Error message: requires property "name"
// Schema says "name" is required:
{ "required": ["name"] }
// Data omits it:
{ "email": "test@example.com" }
A thread on r/webdev about this error has over 150 comments. The most common cause: the schema was generated from one API version but is being used to validate data from another version.
Fix: Check whether the field is genuinely required or was marked required incorrectly during schema generation:
{
"type": "object",
"properties": {
"name": { "type": "string" }
}
// Remove "name" from "required" if it's optional
}
3. "Validation failed for /additionalProperties"
Error message: Property "unknown_field" is not expected
// Schema says no additional properties:
{ "additionalProperties": false, "properties": { "name": { "type": "string" } } }
// Data has an extra field:
{ "name": "Alice", "unknown_field": "value" }
This error increased dramatically when teams switched to additionalProperties: false for stricter validation. The most common root cause: API evolution. You updated the schema to add a new field, but old clients are still sending data without the field, or the schema was deployed before the clients were updated.
On Stack Overflow, this question has 45,000 views.
Fix: Either remove additionalProperties: false if backwards compatibility matters, or add the unknown field to the schema:
{
"type": "object",
"properties": {
"name": { "type": "string" },
"unknown_field": { "type": "string" }
},
"required": ["name"],
"additionalProperties": false
}
4. "Validation failed for /enum"
Error message: value "PENDING" is not defined in the enum
{
"type": "string",
"enum": ["ACTIVE", "INACTIVE", "SUSPENDED"]
}
// Data has:
{ "status": "PENDING" }
This error happens when the enum definition is incomplete. I have seen this in two scenarios: (1) a new status was added to the application but not to the schema, and (2) the enum values are case-sensitive and the data uses a different casing.
Fix: Add the missing value to the enum:
{
"type": "string",
"enum": ["ACTIVE", "INACTIVE", "SUSPENDED", "PENDING"]
}
Or use pattern for case-insensitive matching:
{
"type": "string",
"pattern": "^(ACTIVE|INACTIVE|SUSPENDED|PENDING)$",
"enum": ["ACTIVE", "INACTIVE", "SUSPENDED", "PENDING"]
}
5. "Validation failed for /oneOf"
Error message: No matches found for oneOf schema
{
"oneOf": [
{ "type": "object", "properties": { "type": { "const": "user" }, "name": { "type": "string" } }, "required": ["type", "name"] },
{ "type": "object", "properties": { "type": { "const": "organization" }, "name": { "type": "string" } }, "required": ["type", "name"] }
]
}
// Data has:
{ "type": "user", "name": "Alice", "invalid_field": true }
The data matches neither schema because of the extra invalid_field. Or worse — the data matches both schemas (discriminator not specific enough), and oneOf requires exactly one match.
Fix: Use discriminator for clear branching:
{
"oneOf": [
{ "$ref": "#/definitions/User" },
{ "$ref": "#/definitions/Organization" }
],
"discriminator": { "propertyName": "type" }
}
6. "Validation failed for /format/date-time"
Error message: String "2024/01/01" is not a valid date-time
{
"type": "string",
"format": "date-time"
}
// Data:
{ "created_at": "2024/01/01" }
ISO 8601 requires 2024-01-01T00:00:00Z format. Non-standard date formats are one of the top validation failures across all APIs I have worked with.
On Stack Overflow, this error has over 30,000 views.
Fix: Use the correct ISO 8601 format:
{ "created_at": "2024-01-01T00:00:00Z" }
Or change the schema format:
{
"type": "string",
"pattern": "^\\d{4}/\\d{2}/\\d{2}$"
}
7. "Validation failed for /minLength"
Error message: String "" does not meet minLength constraint of 1
{
"type": "string",
"minLength": 1
}
// Data:
{ "name": "" }
This typically happens when a required field is sent as an empty string instead of being omitted. The fix depends on whether empty strings should be valid for that field.
Fix: Either send the actual value or omit the field entirely.
Related Searches
- json schema validation error
- json schema type mismatch
- json schema additionalproperties false
- json schema oneof validation
- json schema format date-time
- json schema enum errors
- json schema required property
- json schema validation debugging
- ajv error messages
- json schema validation best practices
Frequently Asked Questions
Why does my JSON Schema say "type should be string, got integer"?
The data sent a number where the schema expects a string (or vice versa). Check whether the data source changed recently, or whether the schema is correct for your API version. If the API accepts both types, use oneOf with both string and integer schemas.
How do I handle unknown fields in JSON Schema validation?
Set additionalProperties: false to reject unexpected fields, or omit it (or set it to true) to allow them. If you use additionalProperties: false, keep it updated as your API evolves. Unexpected field errors are a sign that the schema and implementation are out of sync.
What does "No matches found for oneOf schema" mean?
The data did not match any of the schemas listed in oneOf. Check if the discriminator field (if using one) has the expected value, and whether any extra fields in the data cause the match to fail. Test each sub-schema individually to find the issue.
Why does my date-time validation keep failing?
Ensure dates follow ISO 8601 format: YYYY-MM-DDTHH:mm:ssZ. Common mistakes: using slashes instead of dashes, omitting the T separator, and not including the timezone (Z or +HH:mm).
How do I find which field caused a validation error in a large JSON object?
Most validators (like AJV) return an instancePath in the error that shows the exact path to the failing field. Errors also include params with additional context about what was expected. Log the full error object, not just the message.
Final Thoughts
The most common JSON Schema validation errors have simple fixes once you understand what the error message is telling you. Type mismatches, missing required fields, and format violations account for roughly 80% of all validation failures.
The best defense against validation errors is to test your schema against production data before deploying it. A schema that has never been tested with real traffic is guaranteed to produce errors.
Use the JSON Schema Validator on DevFormatters to test your schemas against sample data, and the JSON Formatter to inspect the actual data your API is receiving.