Reputation: 159
Is there any way to define an array as non empty in JSON schema?
Upvotes: 14
Views: 12324
Reputation: 5946
As you can see in the documentation, you can define the minimum amount of items with "minItems": 1
:
{
"id": "http://some.site.somewhere/entry-schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "schema for an fstab entry",
"type": "object",
"properties": {
"options": {
"type": "array",
"minItems": 1, // -> array must not be empty
"items": { "type": "string" },
"uniqueItems": true
},
"readonly": { "type": "boolean" }
}
}
Upvotes: 18