Correct way to define array of enums in JSON schema Correct way to define array of enums in JSON schema arrays arrays

Correct way to define array of enums in JSON schema


Option A is correct and satisfy your requirements.

{    "type": "array",    "items": {        "type": "string",        "enum": ["one", "two", "three"]    }}


According to json-schema documentation, the enumerated values of an array must be included in the "items" field:

{    "type": "array",    "items": {        "type": "string",        "enum": ["one", "two", "three"]    }}

If you have an array that can hold e.g. items of different type, then your schema should look like the one below:

{  "type": "array",  "items": [    {      "type": "string",      "enum": ["one", "two", "three"]    },    {      "type": "integer",      "enum": [1, 2, 3]    }  ]}