Common schema mistakes
Most schemas fail in the same few ways. The schema looks right, the validator says it is valid, and the bad data still gets through — or good data gets rejected for no clear reason. The six mistakes below are the ones we see most often. Each one comes with a before and an after, so you can spot the pattern in your own work.
1. Forgetting required
A schema without required is a polite suggestion: every property is optional, so an empty object {} passes validation without a complaint. The data then travels downstream, and the crash happens three systems later, far from the cause. Decide for each field whether the data can exist without it: an order without an order_id is not an order, so it belongs in required next to the total, while the customer note is genuinely optional.
Before
{
"title": "Order",
"type": "object",
"properties": {
"order_id": { "type": "string" },
"total": { "type": "number" },
"note": { "type": "string" }
}
}
After
{
"title": "Order",
"type": "object",
"required": ["order_id", "total"],
"properties": {
"order_id": { "type": "string" },
"total": { "type": "number" },
"note": { "type": "string" }
}
}
2. Confusing format and pattern
format looks like validation, but in most validators it is only a hint. The JSON Schema specification says format is an annotation by default: a validator may check it, or it may ignore it entirely. Ajv, for example, ignores formats it does not know, such as "phone" — the schema below compiles happily, then accepts "not-a-phone" without blinking. If a value must match a shape, enforce it with pattern, which the validator always checks. Keep format as a hint for humans, never as the only line of defence.
Before
{
"title": "Contact",
"type": "object",
"properties": {
"phone": { "type": "string", "format": "phone" }
}
}
After
{
"title": "Contact",
"type": "object",
"additionalProperties": false,
"required": ["phone"],
"properties": {
"phone": {
"type": "string",
"format": "phone",
"pattern": "^\\+[1-9][0-9]{6,14}$"
}
}
}
3. Forgetting additionalProperties
By default, an object schema accepts any property, including typos. A payload with "emial" instead of "email" passes, the real address is missing, and nobody notices until a customer complains about never receiving anything. Adding "additionalProperties": false turns the typo into a loud, immediate error where it happened. Apply it to every object you control, nested ones included — a typo in a nested address is just as silent.
Before
{
"title": "User",
"type": "object",
"required": ["name", "email"],
"properties": {
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
}
}
After
{
"title": "User",
"type": "object",
"additionalProperties": false,
"required": ["name", "email"],
"properties": {
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
}
}
4. An enum that is too strict
An enum freezes the allowed values at the moment you write the schema. That is exactly what you want for a status with three known values — but it is a trap for anything the real world can extend. A list of payment methods will grow, and every new value will be rejected until someone updates the schema and redeploys. Worse, a model asked for a value outside the list will either fail or invent one inside it. Use enum only for genuinely closed sets; leave open-ended fields as plain strings, with a pattern when the shape is fixed.
Before
{
"title": "Payment",
"type": "object",
"required": ["method"],
"properties": {
"method": {
"type": "string",
"enum": ["visa", "mastercard"]
}
}
}
After
{
"title": "Payment",
"type": "object",
"additionalProperties": false,
"required": ["method"],
"properties": {
"method": {
"type": "string",
"minLength": 1,
"description": "Payment method, for example visa, mastercard, amex, paypal, bank_transfer, or cash."
}
}
}
5. Forgetting nullable types
Real data has gaps: an unstated salary, an end date that has not happened yet, a middle name that does not exist. If the schema says "type": "number" and the data says null, validation fails — not because the data is wrong, but because the schema pretends gaps never happen. The fix is a type list: "type": ["number", "null"] says the value is a number when it is present, and null is an honest answer when it is not. The same applies to strings and objects. And do not confuse this with required: a field can be required and nullable at once — the key must be there, its value may be null.
Before
{
"title": "Job",
"type": "object",
"required": ["title", "salary_max"],
"properties": {
"title": { "type": "string" },
"salary_max": { "type": "number" }
}
}
After
{
"title": "Job",
"type": "object",
"additionalProperties": false,
"required": ["title", "salary_max"],
"properties": {
"title": { "type": "string" },
"salary_max": {
"type": ["number", "null"],
"description": "Yearly salary maximum, or null if not stated."
}
}
}
6. Broken $refs
A $ref is a pointer, and a pointer with a typo points at nothing. The schema still looks fine in your editor, but the validator fails at compile time — or worse, the tool that generated the schema silently drops the broken reference and validates nothing at all. The usual causes are a misspelled definition name, a $defs block renamed on one side only, or a reference to a file that moved. The defence is boring and effective: validate the schema itself every time you change it, and spell $ref targets exactly like the definition. The SchemaBox Validator compiles the schema before validating any data, so a broken $ref fails loudly here, instead of in production.
Before — fragment: no Adress in $defs
"shipping_address": { "$ref": "#/$defs/Adress" }
After
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Order",
"type": "object",
"additionalProperties": false,
"required": ["order_id", "shipping_address"],
"properties": {
"order_id": { "type": "string", "minLength": 1 },
"shipping_address": { "$ref": "#/$defs/Address" }
},
"$defs": {
"Address": {
"type": "object",
"additionalProperties": false,
"required": ["street", "city", "country"],
"properties": {
"street": { "type": "string", "minLength": 1 },
"city": { "type": "string", "minLength": 1 },
"country": { "type": "string", "pattern": "^[A-Z]{2}$" }
}
}
}
}
Conclusion
None of these mistakes is exotic — that is the point. A missing required, a format trusted too far, a door left open, an enum frozen too early, a null nobody planned for, a reference with a typo. Run every schema through the Validator with real data, including the awkward cases, then through the Quality checker, which scores exactly these habits. The best time to catch a schema mistake is before the data that exposes it exists.
Keep reading
- How to write a good JSON Schema — types, required, descriptions, and splitting big objects.
- JSON Schema vs Zod vs Pydantic — three ways to validate, and when to pick each one.
- All guides — back to the guides index.