required : Array<String>
required
Array<String>An object instance is valid against this keyword if every item in the array is the name of a property in the instance.
| Value |
This keyword must be set to a non-empty array of unique strings
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
|---|---|
| Kind | Assertion |
| Applies To | Object |
| Base Dialect | Draft 4 |
| Changed In | None |
| Introduced In | Draft 3 |
| Vocabulary | Validation |
| Specification | https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.5.4.3 |
| Metaschema | http://json-schema.org/draft-04/schema# |
| Official Tests | draft4/required.json |
| Default |
As if it was set to the (invalid) value:
[]
|
| Annotation | None |
| Affected By | None |
| Affects | None |
| Also See |
|
The required keyword restricts
object instances to define the given set of properties.
Common Pitfall
The presence of this keyword does not depend on the
presence of the properties
keyword. The required keyword
mandates that certain properties are present (independently of their value),
while the properties keyword
describes the value of such properties when present.
Remember that JSON Schema is a constraint-driven language.
Therefore, non-object instances successfully validate against this
keyword. If needed, make use of the type keyword to constraint
the accepted type accordingly.
Examples
{
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [ "foo", "bar", "baz" ]
}{ "foo": 1, "bar": 2, "baz": 3 }{ "foo": 1, "bar": 2, "baz": 3, "extra": true }{ "foo": 1, "bar": 2, "extra": true }{}"Hello World"{
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [ "name", "age" ],
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
}
}{ "name": "John Doe", "age": 30 }{ "name": "John Doe", "age": 30, "extra": true }{ "name": "John Doe" }{ "name": 123, "age": "foo" }{}"Hello World"