Reputation: 1
I have a JSON schema
{
"type": "object",
"required": ["version"],
"additionalProperties": false,
"properties": {
"version": {
"type": "string",
"format": "date-time",
"examples": ["2020-08-20T13:57:33.034Z"],
"pattern": "^.{27}$"
}
}}
When I validate the data
{"version": "2025-01-28T07:24:28.090090Z"}
it fails with an error
Found 1 error(s) Message: String '2025-01-28T07:24:28.09009Z' does not match regex pattern '^.{27}$'. Schema path: #/properties/version/pattern
Upvotes: 0
Views: 45
Reputation: 3307
Your string is not 27 characters.
try {26}
and it will validate
format
keyword is not validated by default per the JSON Schema Specification. It's what they call an "annotation", in other words, informational only.
Depending on the implementation you are using, there may exist a flag or options to enable format validation.
EDIT:
more clarification on the simplified ISO8601 date time format:
24 or 27 characters long YYYY-MM-DDTHH:mm:ss.sssZ
or ±YYYYYY-MM-DDTHH:mm:ss.sssZ
Your example data does not follow the ISO format. second ss
and millisecond sss
are only 2 and 3 digits, respectively. Your example has 4 digits, without the optional separator. I believe the validator is dropping the trailing zero because of that reason
Upvotes: 0