Convert INI to JSON

What converting INI to JSON changes, what it can lose (comments, types, key case), and how to check the result is valid and usable.

Converting an INI file to JSON turns a loosely defined configuration format into a strictly defined data format. This makes the settings easier to read from code, validate and pass between tools. The conversion is not neutral, though. INI has no single formal specification, so each converter decides how to handle comments, value types, duplicate keys and keys that sit outside any section. This review explains what changes, what can be lost, and when it is better to keep the original INI.

Is converting INI to JSON right for your use?

The conversion is a good fit when a program, API or build step expects JSON, or when you want to check the structure of the configuration with a JSON validator or schema. The main benefit is predictability: JSON has one documented syntax, so a valid JSON file means the same thing to every compliant parser.

The decisive tradeoff is that JSON has no comments. INI files often carry comments that explain why a setting exists. In a typical conversion those comments are dropped, and you cannot get them back from the JSON alone.

  • Keep the INI file as the source when people edit the configuration by hand and rely on its comments.
  • Keep the INI file when the program that reads it expects INI. Converting gains nothing in that case.
  • Keep the INI file when it uses parser-specific features, such as value interpolation or default sections. A generic converter may flatten or misread these.
  • Convert when JSON is the required input, or when you need a one-time, machine-readable snapshot of the settings.

What the conversion actually changes

This is a structural format conversion. It is not a reverse-text, mirror-text or font effect. The stored characters change: section headers become object keys, key-value lines become properties, and syntax such as brackets, equals signs and semicolons is replaced by JSON's braces, colons, commas and quotes. Nothing depends on how the text is displayed. The output is ordinary plain text that any editor shows the same way.

Here is a small example of the common mapping, where each section becomes a nested object and values are kept as strings:

; database settings
[database]
host = localhost
port = 5432
enabled = true

[paths]
data = /var/lib/app
{
  "database": {
    "host": "localhost",
    "port": "5432",
    "enabled": "true"
  },
  "paths": {
    "data": "/var/lib/app"
  }
}

The comment on the first line does not appear in the output. The port and enabled values remain strings because INI itself has no data types. Some converters instead guess types and output 5432 as a number and true as a boolean. Either result can be correct, depending on what the consuming program expects. Check which behavior your converter uses rather than assuming.

Where converters commonly differ

INI feature | Possible JSON outcomes | What to check
Comments (; or #) | Usually discarded | Whether you need them kept elsewhere
Value types | All strings, or inferred numbers and booleans | Whether 0123, yes/no or empty values are converted as you expect
Keys before any section | Placed at the top level, placed in a default object, or rejected | Where global keys end up
Duplicate keys | Last value wins, first value wins, collected into an array, or an error | That no setting silently disappears
Key case | Preserved or lowercased | Whether the consumer treats keys as case-sensitive
Dotted section names such as [server.http] | Kept as one literal key, or split into nested objects | Which nesting your consumer needs
Array-style keys such as path[] | Collected into an array, or treated as a literal key name | Whether list values survive
Quoted values | Quotes stripped, or kept as part of the string | Whether quote characters leak into the data

A scripted conversion with known behavior

If you need behavior you can inspect, a short script removes the guesswork about a tool's rules. Python's standard configparser module is one documented option. By default it lowercases keys, expands %(name)s references, merges keys from a DEFAULT section into every section, rejects duplicate keys, and raises an error for keys that appear before the first section header. The script below turns off interpolation and keeps key case. All values stay as strings.

import configparser, json

cp = configparser.ConfigParser(interpolation=None)
cp.optionxform = str  # keep key case as written
cp.read("settings.ini", encoding="utf-8")

data = {section: dict(cp[section]) for section in cp.sections()}
print(json.dumps(data, indent=2, ensure_ascii=False))

Keys from a DEFAULT section will still appear inside every section in this output. Remove them deliberately if the consumer should not see them.

Will the result stay readable and usable after copying or sharing?

Because the output is plain text with no styled or substituted characters, it copies and pastes without visual side effects. Search and editing behave normally, and screen readers encounter ordinary characters in normal reading order. No specific screen reader or destination was tested for this review. Long, deeply nested JSON can still be tedious to navigate by ear or on a small screen. That comes from the structure itself, not from any character changes.

  • Encoding: JSON exchanged between systems is expected to be UTF-8. If the INI file uses another encoding or starts with a byte-order mark, decode it correctly first, or non-ASCII text may be corrupted.
  • Escaping: some tools write non-ASCII characters as \u escape sequences. The data is still valid and equivalent, but it is harder for people to read.
  • Validation: run the output through a JSON validator before using it. Common causes of failures are trailing commas, unescaped backslashes in Windows paths, and stray quotes copied from the INI values.
  • Round trips: converting the JSON back to INI will not restore comments, original key order in every tool, or the exact formatting.

Keep a plain INI copy alongside the JSON whenever people will maintain the settings by hand. Treat the JSON as generated output rather than the file you edit.

Using online converters

Configuration files often contain hostnames, credentials or API keys. No evidence was available about how any particular online converter handles, logs or retains pasted input. A tool's appearance or marketing language is not a reliable guide to this. For files with sensitive values, use a local script or an offline tool, or remove secrets before pasting.

Gaps in this review

No specific converter was tested, and no measured results, version details or privacy documentation for named tools were available. The behaviors described here are general properties of the INI and JSON formats and documented behavior of Python's configparser. Confirm how your chosen tool handles types, duplicates, comments and global keys by converting a small sample file that contains each of those cases.