JSON Boolean
A JSON Boolean is a data type that represents one of two possible values:
true
false
Example:
</>
Copy
{
"isEnabled": true,
"isAdmin": false
}
Syntax Rules for JSON Booleans
- No Quotes: Booleans must be written without quotes.
- ✅ Correct:
"isAvailable": true
- ❌ Incorrect:
"isAvailable": "true"
- ✅ Correct:
- Lowercase Only: The values
true
andfalse
must always be written in lowercase.- ✅ Correct:
"isComplete": false
- ❌ Incorrect:
"isComplete": False
- ✅ Correct:
- Standalone Values: Booleans can be used as values in key-value pairs, arrays, or nested objects.
Examples of JSON Booleans
Booleans in Key-Value Pairs:
</>
Copy
{
"isActive": true,
"isVerified": false
}
Booleans in Arrays:
</>
Copy
{
"statuses": [true, false, true]
}
Booleans in Nested Objects:
</>
Copy
{
"user": {
"isOnline": true,
"hasNotifications": false
}
}
Common Use Cases for JSON Booleans
Feature Toggles:
</>
Copy
"darkModeEnabled": true
User Permissions:
</>
Copy
"isAdmin": false
Application Status:
</>
Copy
"isRunning": true
Form Validations:
</>
Copy
"isValidInput": false
FAQs
- What are JSON Booleans used for?
JSON Booleans represent truth values (true
orfalse
) and are commonly used to control logic in applications, such as enabling features or defining conditions. - Can JSON Booleans have quotes?
No, JSON Booleans must not have quotes. If written with quotes, they will be treated as strings. - Are JSON Booleans case-sensitive?
Yes, JSON Booleans are case-sensitive. Always writetrue
andfalse
in lowercase. - Can JSON Booleans be used in arrays?
Yes, JSON Booleans can be used as elements in arrays. - What happens if I write
True
orFalse
instead oftrue
orfalse
?
If you writeTrue
orFalse
, your JSON will be invalid, as JSON Booleans must always be lowercase.