Code Beautifier
must have required property

Fix JSON Schema "must have required property"

Ajv's error when a key in the schema's required array is absent from the data. How to read instancePath, and whether to add the key or relax the schema.

Input that triggers it

{
  "schema": {
    "type": "object",
    "required": ["id", "email"],
    "properties": {
      "id": { "type": "integer" },
      "email": { "type": "string", "format": "email" }
    }
  },
  "data": { "id": 42 }
}
Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

json
Formatted Outputtext

What the error means

A JSON Schema's required keyword lists the property names that an object must contain. Ajv, the validator most JavaScript tooling uses, reports a missing one as must have required property 'email', together with an instancePath that says which object is missing it — an empty path for the root object, /user/address for something nested — and a params.missingProperty field naming the key. The data is otherwise fine; it simply lacks a key the schema insists on.

In the example, the schema requires both id and email, and the data has only id. Validation fails on email at the root.

Why it happens

  • The schema is stricter than the data. Often the schema was written from documentation, or generated from a complete sample, while real documents omit the key for some records.
  • The key is optional in practice but was put in required by default. Many schema generators mark every key seen as required.
  • A nested object is missing the key. The instancePath points at the inner object; the fix belongs there, not at the root.
  • A composition keyword (allOf, oneOf, anyOf) contributes a required list you did not expect, so the key looks optional in one place and required in another.
  • A misspelt key in the data — emial — which the schema correctly treats as missing.

How to fix it

  1. Paste the schema and data into the validator above, as one object with schema and data keys or separated by a === DATA === line. The report lists every failing property with its path, not just the first.
  2. Read instancePath and missingProperty together. /orders/2 plus email means the third order lacks email.
  3. Decide which side is wrong. If the key must be present, fix the data or the producer. If the key is genuinely optional, remove it from required — leave it in properties so its type is still checked when it appears.
  4. To generate a schema whose required list reflects reality, paste several representative records into JSON to JSON Schema: a key absent from any record is left out of required.

The schema that accepts the example:

{
  "type": "object",
  "required": ["id"],
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" }
  }
}

If it still fails

  • With allErrors off, Ajv stops at the first failure; the validator above reports all of them, so fix the whole list in one pass.
  • A required entry that is not declared under properties is legal and still enforced — the key must exist, whatever its type.
  • Pydantic's Field required, serde's missing field, and kotlinx's MissingFieldException are the same contract enforced at the language level; JSON Schema to TypeScript shows which properties become optional (?) from the same schema.

Related errors