data validation_error ai_generated true

JSON Schema enum validation fails due to case sensitivity mismatch

ID: data/json-schema-enum-case

Also available as: JSON · Markdown · 中文
90%Fix Rate
82%Confidence
1Evidence
2023-08-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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#enum

Workarounds

  1. 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']
  2. 85% success Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]
    Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]

中文步骤

  1. Normalize input data to match enum casing before validation: data['status'] = data['status'].lower(); then validate against enum ['active', 'inactive']
  2. Expand enum to include all case variants: "enum": ["Active", "active", "ACTIVE"]

Dead Ends

Common approaches that don't work:

  1. 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.

  2. Using pattern validation with regex for each enum value 70% fail

    This only works in specific validators and is not standard JSON Schema.