data
validation_error
ai_generated
true
JSON Schema 验证失败:format 'date-time' 拒绝带时区偏移的合法 ISO 8601 时间戳
JSON Schema validation fails: format 'date-time' rejects valid ISO 8601 timestamps with timezone offset
ID: data/json-schema-format-date-time-ambiguity
85%修复率
83%置信度
1证据数
2023-08-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ajv 6.12.6 | active | — | — | — |
| jsonschema 4.17.3 | active | — | — | — |
| json-schema-validator 4.0.1 | active | — | — | — |
根因分析
某些验证器(如旧版 ajv)中 JSON Schema 的 'date-time' 格式要求时间戳以 'Z'(UTC)结尾,拒绝像 '+05:30' 或 '-08:00' 这样的合法 ISO 8601 偏移。
English
JSON Schema's 'date-time' format in some validators (e.g., older versions of ajv) requires timestamps to end with 'Z' (UTC) and rejects valid ISO 8601 offsets like '+05:30' or '-08:00'.
官方文档
https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times解决方案
-
Update to a newer validator version that supports RFC 3339 full format: npm install [email protected] (for JavaScript) or pip install jsonschema[format-nongpl] (for Python, which uses rfc3339-validator).
-
Use a custom format validator that accepts all ISO 8601 timezone offsets. Example in Python: from jsonschema import validators; from rfc3339_validator import validate_rfc3339; validator = validators.validate(..., format_checker=validators.Draft7Validator.FORMAT_CHECKER.replaces('date-time', lambda instance: validate_rfc3339(instance)))
无效尝试
常见但无效的做法:
-
60% 失败
Changes the data value, potentially breaking downstream timezone-sensitive logic. Also requires modifying the data source, which may not always be feasible.
-
75% 失败
Validates only the date part, ignoring time entirely, which may not meet the schema's intent.