I am trying to figure out if there is a way to validate that a specific JSON instance has no additional fields outside of the ones declared in the schema.
Let s take this schema as an example:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Client",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"isActive": {
"type": "boolean"
}
},
"required": []
}
I would like to enforce that any JSON of this "type" can only have name, email and isActive. If the following JSON is validated I would like validation to fail:
{
"name": "John",
"email": "[email protected]",
"isActive": true,
"extrafield": 123
}
I am using json-schema-validator to execute the validation, but I have a feeling that more than an implementation issue/assumption with the specific validator I am using, it is my JSON schema that is not enforcing preventing undefined fields.
How can I achieve that? Thanks