0

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

enter image description here

1
  • Cancelling my original answer... simple typo... Your error message date string shows that you gave it 26 characters, not the 27 characters in your quoted data (missing zero before the 'Z'). Credit for answer to @JeremyFiel below please. Commented Jan 29 at 8:23

1 Answer 1

0

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

  • YYYY is the year, with four digits (0000 to 9999), or as an expanded year of + or - followed by six digits. The sign is required for expanded years. -000000 is explicitly disallowed as a valid year.
  • MM is the month, with two digits (01 to 12). Defaults to 01.
  • DD is the day of the month, with two digits (01 to 31). Defaults to 01.
  • T is a literal character, which indicates the beginning of the time part of the string. The T is required when specifying the time part.
  • HH is the hour, with two digits (00 to 23). As a special case, 24:00:00 is allowed, and is interpreted as midnight at the beginning of the next day. Defaults to 00.
  • mm is the minute, with two digits (00 to 59). Defaults to 00.
  • ss is the second, with two digits (00 to 59). Defaults to 00.
  • sss is the millisecond, with three digits (000 to 999). Defaults to 000.
  • Z is the timezone offset, which can either be the literal character Z (indicating UTC), or + or - followed by HH:mm, the offset in hours and minutes from UTC.

src: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format


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

Sign up to request clarification or add additional context in comments.

4 Comments

Count again, it is 27.
I counted again ;-) The OP's error message date (26) contradicts his claimed input date (27), so we were both right. Good spot BTW.
But that's the point: I validate value which originally has 27 length but validator takes it somehow without 0 before Z and as s result the validation fails.
updated the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.