πŸ”’ JSON Data Types
Estimated reading: 3 minutes 31 views

πŸ”˜ JSON Boolean – True/False Values in JSON Explained (2025 Guide)


🧲 Introduction – What is a Boolean in JSON?

In JSON (JavaScript Object Notation), a boolean is a data type that holds one of two values: true or false. Booleans are used to represent binary statesβ€”such as on/off, yes/no, enabled/disabledβ€”making them essential for decision-making in data structures, APIs, and configurations.

🎯 In this guide, you’ll learn:

  • What boolean values are in JSON
  • How to write valid booleans
  • How JSON booleans are used in real examples
  • How they are handled in JavaScript and other programming languages

βœ… JSON Boolean – Format and Syntax

JSON only allows two boolean values:

  • true
  • false

πŸ“Œ Syntax Rules:

  • Must be written in lowercase (true, false)
  • No quotes around the value (unlike strings)
  • Cannot be spelled with capital letters (True, False are invalid)
  • Cannot use numbers like 1 or 0 as a substitute

πŸ§ͺ Example – JSON Object with Booleans

{
  "isActive": true,
  "isAdmin": false,
  "subscribed": true
}

πŸ” Explanation:

  • "isActive": true β†’ The user is active
  • "isAdmin": false β†’ The user is not an admin
  • "subscribed": true β†’ The user has an active subscription

βš™οΈ JSON Boolean in JavaScript

When you parse a JSON string containing booleans in JavaScript, they are automatically converted to native JavaScript boolean types.

βœ… Example:

const json = '{ "loggedIn": true, "premiumUser": false }';
const user = JSON.parse(json);

console.log(user.loggedIn);     // Output: true
console.log(typeof user.loggedIn); // Output: boolean

πŸ” Explanation:

  • JSON.parse() converts the JSON string into a JavaScript object
  • Boolean values remain true or false, not converted to strings

🚫 Invalid JSON Boolean Examples

Here are some common mistakes that cause invalid boolean values in JSON:

{
  "flag": "true"     // ❌ Invalid – value is a string, not a boolean
}
{
  "enabled": True     // ❌ Invalid – JSON booleans must be lowercase
}

βœ… Corrected Version:

{
  "flag": true,
  "enabled": false
}

πŸ“Œ Summary – Recap & Next Steps

Booleans in JSON are simple and powerful. They let you represent two-state values clearly and reliably across different programming environments.

πŸ” Key Takeaways:

  • JSON booleans can only be true or false (no quotes)
  • Always write them in lowercase
  • Do not use "true" as a string or 1/0 as a substitute
  • They automatically map to native booleans in JavaScript and most languages

βš™οΈ Real-world use:

JSON booleans are widely used in user settings, feature toggles, authentication states, and API flags like "success": true.


❓ FAQ – JSON Boolean


❓ What values are valid booleans in JSON?
βœ… Only two: true and false. Both must be lowercase and unquoted.


❓ Can I use "true" as a boolean in JSON?
❌ No. "true" is a string, not a boolean. It will be parsed as text.


❓ Are 1 and 0 valid booleans in JSON?
❌ No. JSON does not allow using integers as boolean values.


❓ How do JSON booleans behave in JavaScript?
βœ… They become native true or false boolean values when parsed with JSON.parse().


Share Now :

Leave a Reply

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

Share

Json Boolean

Or Copy Link

CONTENTS
Scroll to Top