Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Do the elements of 'required' array need to be defined in 'properties' dictionary in JSON schema?
In a JSON schema, do the required
properties need to be a subset of properties
?
E.g. is this a valid schema, even though cookies
isn't mentioned in properties
?
{
"type": "object",
"properties": {
"tea": {
"type": "string"
}
},
"required": [
"tea",
"cookies"
]
}
1 answer
According to my reading of the JSON Schema Spec, the answer is no. required
array can contain elements which are not in the properties dictionary
.
The example schema in question seems to be valid.
Semantically it means that the cookies
property must exist for the JSON to pass validation, but it doesn't matter what type of property it is.
0 comment threads