问题描述
比方说,我有一个将是布尔型的类型,但我不仅要指定它将是布尔型,我还想指定它将具有值false.为了仅指定它将是布尔值,我执行以下操作:
Let's say I have a type that will be boolean, but I don't just want to specify that it will be boolean, I want to specify that it will have the value false. To just specify that it will be boolean I do the following:
{
"properties": {
"some_flag": {
"type": "boolean"
}
}
}
我尝试将上面的布尔值"替换为假"和假"(不带引号),但都无效.
I have tried substituting "boolean" above for "false" and false (without quotes), but neither works.
推荐答案
使用enum
关键字:
{
"properties": {
"some_flag": { "enum": [ false ] }
}
}
此关键字是为此类情况设计的.枚举中的JSON值列表是当前已验证值的可能值列表.在这里,只有一个可能的值:JSON布尔值false.
This keyword is designed for such cases. The list of JSON values in an enum is the list of possible values for the currently validated value. Here, there is only one possible value: JSON boolean false.
这篇关于JSON模式-如何指定布尔值必须为false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!