In JsonSchema, the format value should be set as "full-date" or "date"?

Hakan picture Hakan · Nov 10, 2017 · Viewed 13.8k times · Source

You may use jsonSchemaLint for testing purposes.

I have this JsonSchema, which sets format as "full-date". All Draft-6 validators (Json.Net) accepts the schema as valid.

{
  "title": "MyTestSchema",
  "type": "object",
  "properties": {
    "MyDateValue": {
      "type": "string",
      "format": "full-date",
      "description": "We expect yyyy-MM-dd"
    }
  }
}

But it is unable to identify this Json object is wrong:

{
 "MyDateValue": "2017-10-1"
}

When I switch the schema from "full-date" to "date" only, it works:

 {
  "title": "MyTestSchema",
  "type": "object",
  "properties": {
    "MyDateValue": {
      "type": "string",
      "format": "date",
      "description": "We expect yyyy-MM-dd"
    }
  }
}

Is the one on the top ("full-date") correct term as Json rules? Please refer some documentation.

Answer

Ganesh picture Ganesh · Nov 10, 2017

The value should be date and not full-date please refer this documentation

Following are the valid values

  1. date-time : This SHOULD be a date in ISO 8601 format of YYYY-MM- DDThh:mm:ssZ in UTC time. This is the recommended form of date/ timestamp.

  2. date : This SHOULD be a date in the format of YYYY-MM-DD. It is recommended that you use the "date-time" format instead of "date" unless you need to transfer only the date part.

  3. time : This SHOULD be a time in the format of hh:mm:ss. It is recommended that you use the "date-time" format instead of "time" unless you need to transfer only the time part.

  4. utc-millisec : This SHOULD be the difference, measured in milliseconds, between the specified time and midnight, 00:00 of January 1, 1970 UTC. The value SHOULD be a number (integer or float).

source : here