Can JSON schema enums be case insensitive?

I'm afraid you won't find any elegant solution to this. There was a proposal for case-insensitive enums and several issues were commented.

So if you can not avoid the requirement, regex solutions are the only feasible ones. Another brute-force approach would be to have n complete lists of enum values, one with starting capital letters, other all capital letters, etc. and then use anyOf as you stated. You can automate the creation of this json-schema easily. Obviously it won't be very readable.

Anyway I would try to solve this with a pre-processing step before validation. You might convert to lowercase the required properties if they are present, and then validate. I find a bit forced to use json-schema specification to allow 'dirty' data.


transform method provided in the Ajv-Keywords can be used to have case-insenstive enums.

AjvKeywords(ajv, 'transform');

{
    "type": "array",
    "items": [
        {
            "type": "string",
            "enum": ["NW", "NE", "SW", "SE"],
            "transform": ["toLowerCase"],
        }
    ]
}