Retro-style banner image with the text "What is a JSON Boolean" in glowing blue neon letters on a dark grid background

JSON Boolean Data Type Explained (With Examples)

Understanding the Boolean Data Type in JSON

The Boolean data type in JSON is used to express truth values — true or false. These values are essential for representing binary states like yes/no, on/off, or active/inactive. In programming, Booleans are fundamental to logic and decision-making, and JSON is no exception.

What Is a Boolean in JSON?

A Boolean in JSON must be written in lowercase and without quotes. If you enclose a Boolean value in quotes, it becomes a string and loses its logical meaning.

{
  "subscribed": true,
  "admin": false
}

In the example above, "subscribed" and "admin" are keys paired with Boolean values that indicate logical states.

Rules for JSON Boolean Values

  • Only two possible values: true or false
  • Booleans must be written in lowercase (uppercase versions like TRUE are invalid)
  • Booleans are unquoted — using quotes turns them into strings

Common Use Cases for Booleans in JSON

Boolean values are commonly used in configuration files, APIs, and data payloads to control logic or represent state.

  • User status: "isLoggedIn": true
  • Feature toggles: "darkMode": false
  • Permissions: "isAdmin": true
  • Settings: "notificationsEnabled": true

Valid vs. Invalid Boolean Examples

Example Valid? Reason
true Correct lowercase Boolean
"true" Quoted, so it’s a string
True Capitalized — invalid in strict JSON
false Valid Boolean value

How Booleans Work in Real-World JSON

Booleans are often used in conditional logic within apps and systems. For example, an API might send a user object like this:

{
  "id": 101,
  "emailVerified": true,
  "hasSubscription": false
}

On the frontend, your app can then easily use this data to display different UI states based on the Boolean values.

Best Practices for Using Booleans in JSON

  • Only use Booleans for binary logic — not to represent values like gender, roles, or preferences.
  • Never quote Boolean values ("true" or "false" are strings, not Booleans).
  • Keep key names descriptive to avoid confusion (e.g., "hasLicense" instead of "license").

Summary

The Boolean data type in JSON is simple yet powerful. By using true and false correctly and consistently, you can convey logical state, drive conditional behavior, and streamline your data structure. Just remember — no quotes, no caps, and only two options.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top