json 模式验证不强制类型
json schema validation not enforcing type
我有一个存储 json 的列。我试图确保只有一个对象数组可以存储在此列中,如下面的 json 架构中所述。该模式正在运行,除了我能够将属性 show
保存为字符串,而它应该被强制为布尔值。例如,[{"name"=>"primary_phone", "show"=> "some text"}]
保存正确但不应该保存。我如何强制显示必须是布尔值?
{
"type": "array",
"items": {
"definitions": {
"name": { "type": "string" },
"show": {"type": "boolean"}
},
"required": ["name", "show"]
}
}
您在“项目”下的架构无效。也许您指的是“属性”而不是“定义”?
我有一个存储 json 的列。我试图确保只有一个对象数组可以存储在此列中,如下面的 json 架构中所述。该模式正在运行,除了我能够将属性 show
保存为字符串,而它应该被强制为布尔值。例如,[{"name"=>"primary_phone", "show"=> "some text"}]
保存正确但不应该保存。我如何强制显示必须是布尔值?
{
"type": "array",
"items": {
"definitions": {
"name": { "type": "string" },
"show": {"type": "boolean"}
},
"required": ["name", "show"]
}
}
您在“项目”下的架构无效。也许您指的是“属性”而不是“定义”?