How to convert INI to JSON
An INI file stores settings as key = value lines grouped under [section] headers. JSON stores the same data as objects. To convert INI to JSON, the tool turns each section into an object, each key into a property, and keys that appear before the first section into properties at the top level.
Section names with dots become nested objects by default. This input:
[app]
name = shop
[app.cache]
ttl = 300
[app.cache.redis]
host = 127.0.0.1gives this JSON. The 300 became a number, and the IP address stayed text because it is not a plain number:
{
"app": {
"name": "shop",
"cache": {
"ttl": 300,
"redis": {
"host": "127.0.0.1"
}
}
}
}Everything runs in your browser, so config files with passwords or tokens are not uploaded. See the Privacy Policy.
How the INI parser reads each line
Each line is read on its own, in order. The rules are the ones most INI readers share:
- A line in square brackets starts a section. A comment may follow the closing bracket.
- A key and value are split at the first = or :, so
url = http://host:80/keeps the colons in the value. Spaces around the key and value are trimmed. - Lines that start with ; or # are comments and are left out, because JSON has no comments.
- A value in double quotes keeps its spaces and can hold ; and #. Escapes such as
\n,\t,\"and\u00e9are decoded. A value in single quotes also keeps its spaces and any ; or #, and the quotes are removed, but backslashes inside stay exactly as written, so\nstays a backslash and an n. - A quoted value can run over several lines until the closing quote.
- A byte order mark at the start is ignored, and Windows (CRLF), Unix (LF) and old Mac (CR) line endings all work, even mixed in one file.
When a line cannot be read, such as a header with no closing bracket or a line that starts with =, the tool skips it and adds a warning with the line number. The rest of the file still converts.
INI dialects: php.ini, git config, .editorconfig and Windows INI
INI has no single standard. Each program that reads it set its own rules, and the options here exist to match them. The common cases:
- php.ini uses ; for comments, On and Off for switches, and
extension[] = curllines to build a list. Keep the default Lists setting and Full detect values. - git config writes subsections as [remote "origin"] and indents keys with a tab. The quoted part becomes its own nested object, and its case is kept. A key with no = sign means true, which is the default for Keys without =.
- .editorconfig uses file patterns such as [*.md] and [*.{js,ts}] as section names. Names with * ? { or } are kept whole, so the dot in *.md does not create a nested object.
- Windows INI files read by GetPrivateProfileString use ; comments and no escapes. Keys often contain spaces, such as Window Position, and that is fine here.
- Python configparser files can continue a value on indented lines. Choose Quotes and indented lines under Multi-line values for those.
Here is a short php.ini with a list, using the defaults:
[PHP]
engine = On
memory_limit = 256M
extension[] = curl
extension[] = gd
[Date]
date.timezone = "Europe/Berlin"{
"PHP": {
"engine": true,
"memory_limit": "256M",
"extension": [
"curl",
"gd"
]
},
"Date": {
"date.timezone": "Europe/Berlin"
}
}Dots inside key names, such as date.timezone, are never split. Only section names are nested.
Type conversion pitfalls
INI values are text. Turning them into JSON numbers and booleans is a guess, and some guesses are wrong. Look at this file with Full detect:
country = NO
zip = 01234
version = 1.10
id = 9007199254740993
retries = 3
enabled = yes{
"country": false,
"zip": "01234",
"version": "1.10",
"id": "9007199254740993",
"retries": 3,
"enabled": true
}The country code NO became false, because no is a boolean word in many INI dialects. Switch Values to Numbers, true, false, null only and it stays "NO", while yes stays "yes". The other values show the safety rules that always apply:
- A leading zero, as in 01234, keeps the value as text so zip codes and IDs keep their zero.
- A decimal with a trailing zero, as in 1.10, stays text so version numbers do not turn into 1.1.
- A whole number larger than 9007199254740991 stays text, because JSON readers in JavaScript would round it.
- Forms such as 1e5, 0x1F and +5 stay text. Quoted values are always text.
The Kept as text list names each value that looked like a number but was left as a string, with its line.
Nested sections or flat section names
Nest at dots is right when a program will read the JSON as a tree. Nest at dots and slashes also splits [a/b]. Keep names flat when the section names are labels rather than paths. With flat names, the first example becomes:
{
"app": {
"name": "shop"
},
"app.cache": {
"ttl": 300
},
"app.cache.redis": {
"host": "127.0.0.1"
}
}Nesting can clash. If the file sets a = 1 and later opens a section named [a], a cannot be a value and a section at once. The first one stays, the keys under the clashing part are skipped, and the warning names both lines. Flat names never clash this way.
Repeated keys, repeated sections and strict mode
A key that appears twice in one section is common in hand-edited files. Last wins matches most readers. First wins keeps the earlier value. Collect into an array keeps both, so two port lines give one array that holds 8080 and 9090. Stop with an error refuses to convert and names the lines:
Line 3: "port" in [server] is already set on line 2. Set Duplicate keys to Last wins, First wins or Collect into an array to convert this file.A section that appears twice is merged into the first one by default. Name case set to Lowercase makes Port and port the same key, which matches git config and Windows INI, where names are not case sensitive.
Lists and multi-line values
By default, key[] = value adds to a list and key[name] = value builds an object, as php.ini does. Choose key[] and split on commas to also turn comma lists into arrays, with each item typed on its own:
[cluster]
hosts = web1, web2, 10.0.0.5
ports = 80,443{
"cluster": {
"hosts": [
"web1",
"web2",
"10.0.0.5"
],
"ports": [
80,
443
]
}
}Comma split is off by default because many values hold commas that are not lists, such as Window Position=120,80. For long values, Quotes and trailing backslash joins a line that ends in \ with the next one. Quotes and indented lines joins indented lines with a line break, as Python does. Do not use the indented mode for git config, where every key is indented.
Limits and related converters
The tool reads files up to 2,000,000 characters and section names up to 100 levels deep. It does not expand variables such as ${HOME} or %(name)s, and it does not follow include lines. Inline comments need a space before the ; or #, so a value like #fff or a;b is kept.
If your section headers use double square brackets, the file is TOML, and TOML to JSON is the right tool. Java settings files belong in Properties to JSON, and YAML configs in YAML to JSON. To turn the result into YAML, use JSON to YAML.