JSON模式-如何指定布尔值必须为false? [英] JSON Schema - how do I specify that a boolean value must be false?

查看:210
本文介绍了JSON模式-如何指定布尔值必须为false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一个将是布尔型的类型,但我不仅要指定它将是布尔型,我还想指定它将具有值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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆