I need to define a JSON schema wherein the input can either be a date or empty string.
My current JSON schema is
{
"type": "object",
"required": [
"FirstName",
"DateOfBirth"
],
"properties": {
"FirstName": {
"type": "string"
},
"DateOfBirth": {
"type": "string",
"format": "date"
}
}
}
This allows
{
"FirstName": "Alex",
"DateOfBirth": "1980-10-31"
}
but not
{
"FirstName": "Alex",
"DateOfBirth": ""
}
How can I define the JSON schema so that DateOfBirth allows dates as well as empty string.
Use anyOf to allow for an empty string:
{
"type": "object",
"required": [
"FirstName",
"DateOfBirth"
],
"properties": {
"FirstName": {
"type": "string"
},
"DateOfBirth": {
"anyOf": [
{
"type": "string",
"format": "date"
},
{
"type": "string",
"maxLength": 0
}
]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With