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"
  • Lowercase Only: The values true and false must always be written in lowercase.
    • ✅ Correct: "isComplete": false
    • ❌ Incorrect: "isComplete": False
  • 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

  1. What are JSON Booleans used for?
    JSON Booleans represent truth values (true or false) and are commonly used to control logic in applications, such as enabling features or defining conditions.
  2. Can JSON Booleans have quotes?
    No, JSON Booleans must not have quotes. If written with quotes, they will be treated as strings.
  3. Are JSON Booleans case-sensitive?
    Yes, JSON Booleans are case-sensitive. Always write true and false in lowercase.
  4. Can JSON Booleans be used in arrays?
    Yes, JSON Booleans can be used as elements in arrays.
  5. What happens if I write True or False instead of true or false?
    If you write True or False, your JSON will be invalid, as JSON Booleans must always be lowercase.