In the property definition i need to allow numeric or empty string value, is this expression right for this purpose?
"tprice":{"type":["number",{"enum":[""]}]}
Library, that i use to validate data (Jsv4) generates error for empty string:
Invalid type: string
while i try to set zero length string for this property.
I think the solution for you is the use of anyOf
in the schema.
This is the schema that works for you:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"tprice": {
"anyOf": [
{
"type": "number"
},
{
"type": "string",
"maxLength": 0
}
]
}
}
}
I've used jsonschemalint.com to test it.
{
"tprice": 123
}
and
{
"tprice": ""
}
validates just fine.
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