JSON Schema - how do I specify that a boolean valu

2019-04-18 05:49发布

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.

标签: jsonschema
1条回答
孤傲高冷的网名
2楼-- · 2019-04-18 06:40

Use the enum keyword:

{
    "properties": {
        "some_flag": { "enum": [ 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.

查看更多
登录 后发表回答