39

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.

tadasajon
  • 14,276
  • 29
  • 92
  • 144

2 Answers2

73

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.

fge
  • 119,121
  • 33
  • 254
  • 329
18

As of draft-6, you can use the const keyword. It's similar to enum, but only takes one value.

{
    "properties": {
        "some_flag": { "const": false }
    }
}
Relequestual
  • 11,631
  • 6
  • 47
  • 83