You need to define additionalProperties
in your JSON Schema and set it to false
:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "User",
"description": "A User",
"type": "object",
"properties": {
"name": {
"description": "The user name",
"type": "string"
},
"e-mail": {
"description": "The user e-mail",
"type": "string"
}
},
"required": ["name", "e-mail"],
"additionalProperties": false
}
Now the validation should return false
as expected:
require 'json'
require 'json-schema'
schema = JSON.load('...')
data = JSON.load('...')
JSON::Validator.validate(schema, data)
# => false