INI Boolean Values to JSON: true/false, yes/no, on/off
Understand how INI boolean-style values (true, false, yes, no, on, off) are automatically coerced to JSON boolean types during conversion.
Detailed Explanation
Boolean Value Coercion
INI files commonly use various representations for boolean values. Different applications interpret these differently, but the most common convention treats true, yes, and on as truthy, and false, no, and off as falsy.
Example INI
[features]
enable_logging=true
verbose_mode=yes
auto_update=on
maintenance_mode=false
debug_panel=no
telemetry=off
Generated JSON
{
"features": {
"enable_logging": true,
"verbose_mode": true,
"auto_update": true,
"maintenance_mode": false,
"debug_panel": false,
"telemetry": false
}
}
Coercion Reference
| INI value | JSON value | Notes |
|---|---|---|
true |
true |
Case-insensitive (True, TRUE also work) |
yes |
true |
Common in systemd, Apache configs |
on |
true |
Common in php.ini |
false |
false |
Case-insensitive |
no |
false |
Common in SSH config, Git config |
off |
false |
Common in php.ini |
1 |
1 (number) |
Not coerced to boolean — stays as integer |
0 |
0 (number) |
Not coerced to boolean — stays as integer |
Important Distinctions
The string values "1" and "0" are treated as numeric integers, not booleans. If you need them treated as boolean, quote them in the INI file and handle the conversion in your application logic. The coercion is case-insensitive: TRUE, True, and true all produce JSON true.
Preventing Coercion
If you need to preserve boolean-like words as strings (for example, a key whose value literally should be the string "yes"), wrap the value in quotes: answer="yes". Quoted values bypass type coercion.
Use Case
Converting a php.ini or systemd unit file where boolean-style values like On/Off or yes/no need to be properly represented as JSON booleans for use in a configuration management tool like Ansible or Terraform.