ValidationError: Unknown format 'date-time'
data
validation_error
ai_generated
true
JSON Schema validation rejects valid date strings due to unknown format 'date-time'
ID: data/json-schema-unknown-format
90%Fix Rate
88%Confidence
1Evidence
2023-08-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| JSON Schema draft-04 | active | — | — | — |
| JSON Schema draft-06 | active | — | — | — |
| ajv 8.12.0 | active | — | — | — |
| jsonschema 4.18.0 | active | — | — | — |
Root Cause
JSON Schema draft-04 uses 'date-time' format, but newer drafts (draft-06+) split into 'date' and 'time', and some validators fail to recognize the combined format.
generic中文
JSON Schema draft-04 使用 'date-time' 格式,但更新版本(draft-06+)拆分为 'date' 和 'time',部分验证器无法识别组合格式。
Official Documentation
https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-timesWorkarounds
-
95% success Change 'format': 'date-time' to 'format': 'date' and 'format': 'time' as separate properties in draft-06+.
Change 'format': 'date-time' to 'format': 'date' and 'format': 'time' as separate properties in draft-06+.
-
90% success Use a validator that supports draft-04, e.g., jsonschema with Draft4Validator: from jsonschema import Draft4Validator
Use a validator that supports draft-04, e.g., jsonschema with Draft4Validator: from jsonschema import Draft4Validator
-
85% success Upgrade the JSON Schema library to a version that auto-detects the draft version from $schema.
Upgrade the JSON Schema library to a version that auto-detects the draft version from $schema.
中文步骤
Change 'format': 'date-time' to 'format': 'date' and 'format': 'time' as separate properties in draft-06+.
Use a validator that supports draft-04, e.g., jsonschema with Draft4Validator: from jsonschema import Draft4Validator
Upgrade the JSON Schema library to a version that auto-detects the draft version from $schema.
Dead Ends
Common approaches that don't work:
-
Adding 'format': 'date-time' to schema definitions
90% fail
This is the problematic format itself; validators that don't support it will still reject it.
-
Using 'pattern' instead of 'format' with a regex for datetime
40% fail
While this works for validation, it does not fix the schema compatibility issue and may be overly restrictive or permissive.