JSON Schema Required Fields: Examples and Common Mistakes
Last updated:
The JSON Schema required keyword is an array of property name strings that must be present in the validated object — missing any 1 of them fails validation immediately. It belongs alongside the properties keyword on the same object schema: "required": ["id", "email"]. An empty required: [] makes no field mandatory. Adding a property to required only checks presence — it does not constrain the value; you still need an entry in properties for type validation. This guide covers required vs optional fields, the absent vs null distinction (a null value satisfies required; an absent key does not), conditionally required fields using if/then/else, nested object required arrays, the dependentRequired keyword for field dependencies, and common validator behavior differences between Ajv, jsonschema, and tv4.
Testing required fields? Paste your schema and sample data into Jsonic's JSON Schema Validator to see exactly which property is missing.
Validate JSON SchemaBasic required example
{
"type": "object",
"properties": {
"id": { "type": "integer" },
"email": { "type": "string", "format": "email" },
"name": { "type": "string" }
},
"required": ["id", "email"]
}This requires id and email. The name property is allowed but optional.
Required does not define type
required only checks whether a property exists. The property's value is checked by its schema under properties.
{
"type": "object",
"properties": {
"active": { "type": "boolean" }
},
"required": ["active"]
}Nested required fields
For nested objects, each object has its own required array.
{
"type": "object",
"properties": {
"profile": {
"type": "object",
"properties": {
"displayName": { "type": "string" }
},
"required": ["displayName"]
}
},
"required": ["profile"]
}The top-level required makes profile mandatory. The nested required makes profile.displayName mandatory.
Required fields in arrays of objects
Put required inside the items object schema so every item is checked. The array of objects guide covers this pattern in more depth.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"sku": { "type": "string" },
"quantity": { "type": "integer", "minimum": 1 }
},
"required": ["sku", "quantity"]
}
}Common mistakes
| Mistake | Fix |
|---|---|
Writing "required": true | Use an array: "required": ["id"] |
| Putting required inside a property schema | Put it on the parent object schema |
| Expecting required to reject null | Add a type rule that excludes null |
| Forgetting nested required arrays | Add required to each nested object schema |
Validate required fields online
Use Jsonic's JSON Schema Validator to test required-field errors before shipping an API contract or config schema.
Open Schema ValidatorFrequently asked questions
How do I mark a field as required?
Use the required keyword on the object schema with an array of property name strings: {"required": ["id", "email"]}. Properties not listed in required are optional.
Does required apply to nested objects?
Each object needs its own required array. The top-level required only applies to top-level keys. Add a separate required inside each nested object schema to require its properties.
What happens if a required field is missing?
The validator reports an error identifying which property is missing. Ajv includes instancePath (the parent object path) and params.missingProperty (the absent key). All missing required fields are reported together.
What is the difference between required and not having a property?
A property in properties but not in required is optional. A property in required but not properties must be present but can have any value. The required keyword only checks key presence, not the value.
Can I make all properties required by default?
There is no built-in keyword for this. You must list each required property explicitly. Some code generation tools can auto-populate required with all defined property names when generating schemas.
How does required interact with additionalProperties: false?
required specifies which keys must be present; additionalProperties: false rejects keys not listed in properties. Together they create a strict schema: all listed fields must appear and no extra fields are allowed.
Recommended reading
- Designing Data-Intensive Applications (2nd Edition) — Martin Kleppmann & Chris RiccominiThe modern classic on data systems — encoding formats, schemas, replication, and stream processing.
- JavaScript: The Definitive Guide (7th Edition) — David FlanaganThe complete reference for the language JSON came from — serialization, async, and the full standard library.
As an Amazon Associate, Jsonic earns from qualifying purchases.