A boolean is a data type that can have only two values:
truefalseBooleans are used when the answer to a question is simply Yes or No.
For example:
The answer to each of these questions is either true or false.
{
"isStudent": true,
"hasHomework": false
}
In this example:
"isStudent": true means the person is a student."hasHomework": false means the person does not have homework.JSON allows only these two boolean values.
✅ Correct
{
"isOnline": true
}
✅ Correct
{
"isOnline": false
}
❌ Wrong
{
"isOnline": "true"
}
Why is it wrong? "true" is a string (text) because it is inside quotes. A boolean should not be written inside quotation marks.
Boolean values must be written without double quotes.
✅ Correct
{
"isAvailable": false
}
❌ Wrong
{
"isAvailable": "false"
}
Why is it wrong? "false" is treated as text, not as a boolean value.
The words true and false must always be written in lowercase.
✅ Correct
{
"isMember": true
}
❌ Wrong
{
"isMember": True
}
❌ Wrong
{
"isMember": FALSE
}
Why is it wrong? JSON only accepts the lowercase words true and false.
| Boolean Value | Meaning |
|---|---|
true | Yes, correct, or enabled |
false | No, incorrect, or disabled |
true or false."true" and "false" are strings, not booleans.