Reputation: 266
Im trying to use json schema, here with a simple example. Im using the site: http://www.jsonschemavalidator.net/
Schema:
{
'Foods':
{
'type': 'array',
'items':
{
'GoodFoods': { 'type':'string' },
'NastyFoods': { 'type':'string' },
'BlendFoods': { 'type': 'string' }
},
'required': ['BlendFoods'],
}
}
Input JSON:
{
"Foods":
[
{
"GoodFoods": "Pasta",
"NastyFoods": true,
}
]
}
The idea here is that it should complain that "BlendFoods" property is missing and that the NastyFoods is a boolean not a string. But instead it says "No errors found. JSON Validates against the schema". That is not what I want.
I tried so much with this but cant figure out what Im doing wrong in the schema, any ideas?
Best regards Rob
Upvotes: 0
Views: 2358
Reputation: 466
There's an extra comma after true.
try this:
{
"Foods":
[
{
"GoodFoods": "Pasta",
"NastyFoods": true
}
]
}
Upvotes: 0
Reputation: 1630
The corrected schema:
{
"type": "object",
"properties": {
"Foods": {
"type": "array",
"items": {
"type": "object",
"properties": {
"GoodFoods": {
"type": "string"
},
"NastyFoods": {
"type": "string"
},
"BlendFoods": {
"type": "string"
}
},
"required": [
"BlendFoods"
]
}
}
}
}
Please see this site for reference and help.
Upvotes: 5