Write INI files with the JSON to INI converter
The JSON to INI converter maps a JSON object onto the section-and-key layout of an INI file. Scalar values at the top level are written first as global keys, every nested object becomes a [section], deeper objects become dotted sections such as [server.tls], and arrays are written as repeated key[] = value lines, the PHP convention.
It is handy when you keep settings in JSON but need to produce a php.ini fragment, a setup.cfg, a game or desktop-app config, or any legacy tool that only reads INI.
Example
Input:
{
"title": "Acme",
"server": {
"host": "0.0.0.0",
"ports": [80, 443],
"tls": { "cert": "/etc/ssl/a.pem", "enabled": true }
},
"db": { "password": "p;ss#1", "note": null, "empty": "" },
"logging": { "file": { "path": "/var/log/app.log" } }
}
Output:
title = Acme
[server]
host = 0.0.0.0
ports[] = 80
ports[] = 443
[server.tls]
cert = /etc/ssl/a.pem
enabled = true
[db]
password = "p;ss#1"
note =
empty = ""
[logging.file]
path = /var/log/app.log
How the mapping works
- Section headers are only written when needed.
logginghas no values of its own, so the output jumps straight to[logging.file]instead of printing an empty[logging]. - Quoting: values containing
;,#,=or", values with leading or trailing spaces, and empty strings are wrapped in double quotes so INI parsers do not treat part of them as a comment. - null becomes an empty value (
note =), while""is written as""so the two stay distinguishable. - Numbers and booleans are written as plain text; INI has no types, so the reading program decides how to interpret them.
Edge cases
- Top-level arrays are rejected with "INI needs a JSON object at the top level", since INI has no way to represent a list of documents.
- Objects inside arrays cannot become sections, so they are stored as JSON text:
list[] = "{\"x\":1}". Restructure the data if the target app needs real sections. - Dotted section names are a convention. PHP's
parse_ini_fileand Python'sconfigparserread[server.tls]as a single section with a dot in its name, which is usually what you want.
To go the other way, use INI to JSON. If you are free to choose the format, JSON to TOML gives you INI-like syntax with real types and nested tables. Validate your source first with the JSON validator.
Privacy
The conversion runs in your browser; your configuration is not uploaded.