data
validation_error
ai_generated
true
JSON Schema enum validation fails due to case sensitivity mismatch
ID: data/json-schema-enum-case
90%Fix Rate
82%Confidence
1Evidence
2023-08-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| JSON Schema Draft 2020-12 | active | — | — | — |
| Ajv 8.12.0 | active | — | — | — |
| Python jsonschema 4.17.0 | active | — | — | — |
Root Cause
JSON Schema enum validation is case-sensitive by default, but input data may contain values with different casing (e.g., 'Active' vs 'active'), causing rejection.
generic中文
JSON Schema枚举验证默认区分大小写,但输入数据可能包含不同大小写的值(例如'Active' vs 'active'),导致拒绝。
Official Documentation
https://json-schema.org/understanding-json-schema/reference/generic.html#enumWorkarounds
-
95% success Normalize input data to match enum casing before validation: data['status'] = data['status'].lower(); then validate against enum ['active', 'inactive']
Normalize input data to match enum casing before validation: data['status'] = data['status'].lower(); then validate against enum ['active', 'inactive']
-
85% success Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]
Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]
中文步骤
Normalize input data to match enum casing before validation: data['status'] = data['status'].lower(); then validate against enum ['active', 'inactive']
Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]
Dead Ends
Common approaches that don't work:
-
Adding 'caseInsensitive': true to the schema definition
85% fail
JSON Schema does not support case-insensitive enum matching natively; custom keywords may not be portable.
-
Using pattern validation with regex for each enum value
70% fail
This only works in specific validators and is not standard JSON Schema.