sudha
sudha

Reputation: 159

Defining an array as non empty in json schema

Is there any way to define an array as non empty in JSON schema?

Upvotes: 14

Views: 12324

Answers (1)

Matthias Burger
Matthias Burger

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

Related Questions