When an API rejects a JSON payload, the useful question is not only “what failed?” but “which value, rule, and contract caused the failure?” This JSON Schema validation guide provides a repeatable workflow for validating JSON against a schema, interpreting errors, and fixing invalid API payloads before they reach a service. Use it with a JSON schema validator online, a local validator in your test suite, or an API client that supports contract checks.
Overview
JSON syntax and JSON Schema validation are separate checks. A JSON formatter or parser can confirm that braces, commas, strings, numbers, arrays, and objects are syntactically valid. It cannot confirm that a payload contains the right fields, uses the expected types, or satisfies business constraints.
For example, this document is valid JSON:
{"userId": "42", "active": "yes"}It may still be invalid against a schema that requires userId to be an integer and active to be a boolean. Schema validation compares an instance—the JSON document—with rules describing the accepted structure.
Before investigating an error, identify three inputs:
- The instance: the exact JSON sent to or received from the API, without manually “cleaning up” values.
- The schema: the version, definitions, required properties, types, formats, and constraints that apply.
- The validator: the library, online tool, API gateway, or test runner performing the check.
Validator behavior can differ. Supported JSON Schema drafts, format checking, custom keywords, reference resolution, and error wording are not necessarily identical across tools. If the API uses OpenAPI, also check which schema dialect and version its implementation supports rather than assuming that every JSON Schema keyword behaves the same way.
A practical workflow is: parse the JSON, confirm the schema draft, validate the complete document, read the path in each error, fix the smallest incorrect value, and run the check again. For broader request troubleshooting, pair this process with the API debugging checklist.
Checklist by scenario
When the payload is rejected immediately
- Copy the exact request body, including empty strings, nulls, arrays, and numeric values.
- Run a syntax check first. A missing comma or unclosed string is not a schema failure.
- Confirm that the request body is actually JSON and that the client is sending the expected content type.
- Validate against the same schema version used by the API or contract test.
- Compare the validator's error path with the payload path, such as
/customer/address/postcode.
When a required field error appears
Find the relevant required array and check the property's immediate parent object. A common mistake is adding the field at the wrong nesting level.
{"type":"object","required":["email"],"properties":{"email":{"type":"string"}}}This schema requires email in the root object. A payload such as {"profile":{"email":"dev@example.test"}} does not satisfy it because the field is nested under profile. Also distinguish between a missing property and a property whose value is null. Unless the schema explicitly permits null, those are different cases.
When a type error appears
Check whether the producer is serializing values as strings. JSON has distinct string, number, integer, boolean, object, array, and null types. The values "100" and 100 are not interchangeable for a schema that declares type: integer. Likewise, "false" is a string, not the boolean false.
- Use a number for quantities and numeric identifiers when the contract defines them as numeric.
- Use a boolean for flags instead of
"true"or"false". - Do not rely on a validator to coerce types unless that behavior is explicitly configured and matches the API.
When nested objects or arrays fail
Walk the error path from left to right. For an error at /orders/1/items/0/quantity, inspect the second order, then its first item, then quantity. Check both the container and its contents:
itemsmay needtype: array.- The array may have
minItems,maxItems, oruniqueItemsconstraints. - The
itemsschema defines what each element must contain. - Nested objects may have their own
required,properties, oradditionalPropertiesrules.
When a format error appears
Inspect values such as dates, date-times, email addresses, URIs, UUIDs, or hostnames. Do not assume that every validator checks every format by default. Some tools treat format as informational unless format assertions are enabled, while others apply stricter checks. Confirm the validator configuration and the API's actual expectations before changing a value.
When the schema contains references
Resolve $ref targets before interpreting the failure. The effective rule may live in a shared definition, a separate file, or a component referenced several levels below the request body. If an online validator reports an unresolved reference, provide the complete schema bundle or use a local validation setup that can load the referenced documents.
What to double-check
Schema version and dialect
Record the declared draft, such as draft-07, 2019-09, or 2020-12, and confirm that the selected validator supports it. Keywords and vocabulary behavior can depend on the draft. OpenAPI documents may also use a particular schema dialect or a subset of JSON Schema features.
Required versus allowed properties
required controls which properties must be present. It does not make every property mandatory by default. Conversely, a payload can fail because it contains an unexpected property when the schema or validator applies a restrictive additionalProperties or related rule. Decide deliberately whether forward-compatible extra fields should be accepted.
Constraints beyond type
After checking the basic type, review minLength, maxLength, pattern, minimum, maximum, multipleOf, minItems, and maxItems. A string can have the correct type but still fail a pattern or length rule. A number can be numeric but outside the permitted range.
For pattern-based rules, test representative valid and invalid values separately. The regex tester workflow can help isolate a regular expression, but remember that the validator's regular-expression behavior and the application's surrounding logic still need to be tested together.
Combinations and conditional rules
Keywords such as oneOf, anyOf, allOf, not, if, then, and else can produce confusing messages. Read the nested sub-errors rather than relying only on the top-level summary. With oneOf, for example, the instance may match none of the alternatives—or more than one when exactly one is required.
Error reporting and sensitive data
Prefer errors that include an instance path, schema path, keyword, and a short explanation. Keep the original payload available for debugging, but remove credentials, access tokens, personal data, and other secrets before sharing it in a ticket or online validator. Validation failures should not become a reason to expose production data. Review secret-handling practices separately in the environment variables versus secret managers guide.
Common mistakes
- Formatting instead of validating: A JSON beautifier improves readability but does not check the document against a schema.
- Using the wrong schema: Create, update, response, and event payloads may have similar but different contracts.
- Reading only the first error: Fixing one issue can reveal another. Capture all actionable errors when the validator supports it.
- Assuming null means missing: A present property with a null value must be allowed explicitly when the contract requires that distinction.
- Ignoring array indexes: Error paths often point to a specific element, not the array as a whole.
- Trusting coercion: A local tool may convert strings to numbers or booleans while the production API rejects them.
- Overusing permissive schemas: Accepting every extra field can hide misspellings such as
userNmae. Choose strictness based on compatibility and ownership. - Testing only a happy path: Include missing fields, wrong types, boundary values, empty arrays, nulls, extra properties, and malformed formats.
Store representative payloads as fixtures and run validation in code review or CI. This turns an online developer tool from a one-time debugging aid into part of a repeatable API workflow. For teams maintaining deployment configuration, the same review discipline is useful alongside a Helm chart review checklist or a CI failure triage process.
When to revisit
Revisit this validation checklist whenever an API adds, removes, renames, or changes the type of a field. Also review it when a schema draft changes, a validator is upgraded, format assertions are enabled, an OpenAPI version changes, or a gateway begins enforcing rules that were previously advisory.
Before a planned release or seasonal planning cycle, run a small contract review:
- List the schemas currently used by producers, consumers, tests, and gateways.
- Validate current fixtures against the intended schema and record every exception.
- Test old and new payloads when compatibility matters.
- Confirm that local, CI, staging, and production validators use compatible settings.
- Update examples and error-handling documentation with the paths developers will actually see.
Keep a short regression set containing one valid payload and one focused failure for each important rule: missing required field, wrong type, invalid format, boundary violation, unexpected property, nested-object failure, and array-item failure. Run it whenever the workflow or validation tool changes. That small set makes JSON Schema validation errors easier to locate and prevents a contract fix from silently weakening the API.
Use this final checklist before declaring a payload ready: parse the exact JSON, confirm the schema draft, validate the complete instance, inspect every error path, verify formats and references, test boundary cases, remove secrets from shared examples, and automate the checks where the payload is produced.