json schema date-time does not check correctly json schema date-time does not check correctly json json

json schema date-time does not check correctly


For Python's jsonschema library, specify the format checker when calling validate:

jsonschema.validate(data, schema, format_checker=jsonschema.FormatChecker())

To validate a date-time format, the strict-rfc3339 package should be installed.

See Validating Formats.


Validation with "format" is optional. This is partly because schema authors are allowed to completely make up new formats, so expecting all formats to be validated is not reasonable.

Your library should (if it is decent) have a way to register custom validators for particular formats. For example, the tv4 validation library (in JavaScript) has the tv4.addFormat() method:

tv4.addFormat('date-time', function (data) {    return isValidDate(data);});

Once you've done this, then "format": "date-time" in the schema should validate dates correctly.


It is highly likely that the implementation of JSON schema validation that you're using is requiring the T separator between the date and time components. This is a staple of the RFC3339 spec and ISO8601 which it is based upon. While both have provisions for omitting the T, they both make it something that can be done by agreement, rather then a mandatory thing to support. (Go figure.)

Also, RFC3339 does require that you include either a time zone offset or a Z to indicate UTC. This locks it down to a particular moment in time, rather than a human representation of one in some unknown time zone. Since you have required neither, that's likely while it has failed validation.

From the JSON Schema spec:

7.3.1.2. Validation

A string instance is valid against this attribute if it is a valid date representation as defined by RFC 3339, section 5.6 [RFC3339].