When an API payload fails JSON Schema validation, the error is usually traceable to a small mismatch: a value has the wrong type, a required property is missing, an array contains an unexpected item, or the validator is interpreting the schema differently than you expect. This guide provides a reusable checklist for diagnosing JSON validation errors, with examples for common types, formats, nested objects, arrays, and composed schemas.
Overview
JSON Schema describes the structure and constraints a JSON document must satisfy. It can define property names, data types, required fields, allowed values, string patterns, numeric limits, array contents, and relationships between alternatives. A JSON Schema validator compares an instance—the JSON payload—with those rules and reports one or more validation failures.
Start by separating two different problems:
- Invalid JSON: The document cannot be parsed because of syntax errors such as a missing comma, an unquoted property name, or a trailing character.
- Valid JSON that fails its schema: The document parses correctly, but one or more values do not meet the schema's constraints.
An online JSON formatter can help confirm syntax and make a large payload readable, but formatting alone does not prove that the document conforms to a schema. Use a JSON Schema validator with the intended schema version and inspect the complete error path, not only the first message shown by a tool.
For API work, schema validation is most useful when the schema and payload are tested together in development and CI. It can catch contract drift before a request reaches a service, while also making rejected requests easier to explain to callers.
Checklist by scenario
1. The payload does not parse as JSON
- Run the payload through a JSON formatter or parser.
- Read the reported line and column, then inspect the character immediately before it. The visible error location is often after the actual mistake.
- Check for single quotes, comments, unquoted keys, trailing commas, and accidental text before or after the JSON document.
- Confirm that strings use escaped quotation marks and valid escape sequences.
For example, this is not valid JSON:
{ "name": "Ada", }
Remove the trailing comma:
{ "name": "Ada" }
2. A value has the wrong type
JSON distinguishes between strings, numbers, booleans, objects, arrays, and null. A value that looks reasonable to a person can still violate the schema.
{
"port": "8080",
"enabled": "true",
"tags": "api"
}
If the schema expects port to be an integer, enabled to be a boolean, and tags to be an array, the corrected payload is:
{
"port": 8080,
"enabled": true,
"tags": ["api"]
}
Do not assume that a validator will coerce strings into numbers or booleans. Coercion is implementation-specific and can hide client defects. Prefer explicit conversion in the client or service unless your validation workflow deliberately defines coercion behavior.
3. A required property is missing
The required keyword checks that named properties exist. It does not require every property listed under properties to be present.
{
"type": "object",
"required": ["id", "email"],
"properties": {
"id": { "type": "string" },
"email": { "type": "string" },
"displayName": { "type": "string" }
}
}
Here, displayName is optional, but id and email must be included. Also distinguish a missing property from a property set to null. If a field may be null, express that explicitly in the schema and confirm that the validator's supported syntax matches the schema version you are using.
4. A string fails a format or pattern rule
Strings may be restricted by minLength, maxLength, pattern, or a semantic format. A format such as email, date, or uri should be treated as a validation rule only when your validator is configured to enforce it. Validators can differ in which formats they recognize and how strictly they check them.
{
"type": "object",
"properties": {
"createdAt": { "type": "string", "format": "date-time" }
},
"required": ["createdAt"]
}
Check whether the value includes the expected date and time structure, whether the API uses UTC or an offset consistently, and whether the validator has format checking enabled. For custom identifiers, a regular expression may be more appropriate than a built-in format, but test the expression against valid and invalid examples.
5. An array contains unexpected items
For arrays, inspect both the array itself and the schema for its items. Common failures include supplying an object where an array is expected, using the wrong item type, or exceeding minItems or maxItems.
{
"type": "array",
"minItems": 1,
"items": { "type": "string" }
}
This schema accepts ["read", "write"] but rejects ["read", 2]. If each position has a different purpose, confirm that the schema intentionally uses tuple-style item rules rather than one shared item schema.
6. A nested object fails validation
Follow the error path from the root to the failing value. A path such as /user/address/postcode identifies the nested property that needs attention. Check the parent object's type first, then its required fields, then the child constraints.
Nested failures are often caused by a mismatch between the API's documented shape and the client model. For example, the API may expect address to be an object, while a client sends a serialized JSON string. Decode or construct the nested object before validation rather than validating a string that merely contains JSON-looking text.
7. Composition keywords produce confusing results
When a schema uses allOf, anyOf, oneOf, or not, inspect each branch separately. allOf requires every subschema to pass. anyOf requires at least one branch. oneOf requires exactly one branch, so a payload can fail because it matches none or because it matches multiple alternatives.
For composed schemas, temporarily validate the payload against each branch with descriptive test cases. Add a discriminator or mutually exclusive property when alternatives overlap. This makes both the API contract and the validator's error output easier to understand.
What to double-check
| Check | Why it matters | Practical action |
|---|---|---|
| Schema version | Keywords and accepted syntax can vary between drafts and validator implementations. | Declare the intended schema version and configure the validator accordingly. |
| Error path | The top-level message may hide the exact failing property. | Read the instance path and schema path for every reported error. |
| Unknown properties | Extra fields may be allowed or rejected depending on the object rules. | Check whether additionalProperties or a newer object rule is configured as intended. |
| Formats | Format support and enforcement can differ across tools. | Test representative values and document whether formats are annotations or enforced constraints in your workflow. |
| Nullability | Missing, null, empty string, and empty array are different values. | Define each accepted state explicitly instead of treating them as interchangeable. |
| API encoding | A correct JSON document can be changed by transport or serialization. | Inspect the actual request body, content type, and client serialization output. |
When debugging an API, save the exact payload received by the server, the schema used for validation, the validator configuration, and the complete error list. A reduced reproduction is valuable, but keep the original request available so that transport or serialization problems are not lost.
Common mistakes
- Confusing JSON syntax with schema validation: A formatter can show that JSON parses, but it cannot confirm business or structural constraints.
- Reading only the first error: Fixing one issue may reveal several independent failures. Review all errors when the validator provides them.
- Assuming property order matters: JSON object property order should not be used to satisfy a schema. Validate names and values instead.
- Using examples as rules: An
examplevalue documents a possibility; it does not generally constrain the instance unless a separate rule does so. - Relying on implicit coercion: Converting
"42"to42may make a test pass while leaving the producing client incorrect. - Overusing strictness: Rejecting every unknown property can make harmless client evolution difficult, while allowing every property can conceal misspellings. Choose the policy deliberately for each boundary.
- Ignoring contract tests: A schema checked only in a local tool can drift from the API implementation. Run representative validation in automated tests and deployment checks.
For broader API investigations, pair schema validation with status-code, authentication, and request-body checks. The JSON API debugging guide provides a useful workflow for separating these layers. If the schema is part of a public contract, consider adding contract tests that compare provider responses and consumer expectations before deployment; see the OpenAPI contract testing workflow.
When to revisit
Revisit this checklist whenever an endpoint is introduced, a request or response model changes, or a validator or schema draft is upgraded. It is especially useful before seasonal planning cycles when teams review API contracts, CI checks, and shared developer tooling.
- Record the schema version and validator version used by each service.
- Keep valid, invalid, boundary, and backward-compatibility fixtures in source control.
- Run validation against the serialized request and response, not only an in-memory object.
- Review error paths and messages after changing nested objects, alternatives, formats, or additional-property rules.
- Update examples and client documentation when the contract changes.
Before closing a validation incident, reproduce the original failure, identify the first incorrect assumption, and add a regression case. That final step turns a one-time debugging session into a durable developer utility: the next schema change or rejected API payload can be diagnosed with less guesswork.