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.
The boolean data type is used to specify a true or false value. Note: Legal values for boolean are true, false, 1 (which indicates true), and 0 (which indicates false).
Short answer, yes that is the proper way to send the JSON. You should not be placing anything other than a string inside of quotes. As for your bool value, if you want it to convert straight into a bool, than you do not need to include the quotes.
So even if you send a parameter like “active=true”, it is still a string, this is how the HTTP protocol works. Hope this helps clarify the mystery. var bflag = Boolean(“true”); var bflag1 = Boolean(“false”);
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.
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 } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With