1
votes

I want my date format to be MM-dd-yyyy, and as you said format=date takes yyyy-MM-dd. so can i create my own custom format=customdate? if yes, then how can it be acheived? here's my requirements and my problems Requirement Store date in MM-dd-yyyy format into my JSON object as type string after validating my JSON object with the JSON schema Problem Getting ErrorType=Format validation error when I try to validate MM-dd-yyyy date with the JSON schema

The Validation Error which I am getting is String '09-09-1966' does not validate against format 'date'.

MY JSON SCHEMA LOOKS LIKE THIS

"title": myjsonschema,
"type": "object",
"properties": {
  "birthDate": {
    "type": [
             "string",
             "null"
            ],
    "format": "date",
    "pattern": "^(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[01])\\-\\d{4}$",
    "message": {
             "pattern": "This field should be in mm-dd-yyyy format"
    }
  }
}

MY JSON OBJECT

{"birthday":"09-09-1966"}
1
I have already answered your question on the JSON Schema Slack server... but OK.Relequestual
In future, please provide actual error messages.Relequestual

1 Answers

0
votes

You will have to look at the implementation you are using.

format is an annotation only, meaning by default it does nothing in terms of validation.

Anything it does do in terms of validation is implementation specific.

If it DOES do something, JSON Schema spec does specify what that should be. "date" is the "full-date" production from RFC3339, which is date-fullyear "-" date-month "-" date-mday. Your date doesn't start with the year.