toolhq.io

All posts
7 min readby Jameel Haider

JSON vs TOML: choosing a config format, and converting between them

JSON and TOML both describe structured data, but they were designed for different jobs. Knowing which fits configuration, and which fits data exchange, saves a lot of friction.

Where JSON struggles as config

JSON is excellent for machines talking to machines: it is everywhere, every language parses it, and its structure is unambiguous. As a human-edited config format, though, it has two real pain points: it has no comments, so you cannot annotate why a setting exists, and its strict syntax (quotes on every key, no trailing commas) makes hand-editing error-prone. Those are exactly the things you want when a person maintains a config file.

JSON also has no native date type and no integers distinct from floats, so a timestamp or a version number ends up as a quoted string that every consumer has to parse by hand.

What TOML adds

TOML was designed specifically for configuration that humans write. It supports comments, reads more like an INI file, and has first-class syntax for the things configs actually contain: dates, nested tables, and arrays. A TOML file tends to be more readable and more forgiving to edit by hand.

Compare the same configuration in both formats. In JSON:

{
  "server": { "host": "0.0.0.0", "port": 8080 },
  "database": { "url": "postgres://localhost/app", "pool": 10 }
}

And in TOML:

# server settings
[server]
host = "0.0.0.0"
port = 8080

[database]
url = "postgres://localhost/app"
pool = 10

The TOML version carries a comment, drops the punctuation noise, and groups settings under named tables that read top to bottom.

The quick comparison

JSONTOML
CommentsNoYes
Dates and timesString onlyNative
Trailing commasRejectedAllowed in arrays
Deeply nested dataUniform, clearGets verbose
UniversalityEvery languageCommon, not universal
Best atData exchangeHuman-edited config

Where TOML gets awkward

TOML shines for flat-to-moderate structures. It gets clumsy when data is deeply nested or highly dynamic, because every level needs a bracketed table header and arrays of tables use a double-bracket syntax ([[servers]]) that is easy to misread:

[[servers]]
name = "web1"
[[servers]]
name = "web2"

For data that is genuinely tree-shaped or generated by a program, JSON's uniformity is the advantage, which is why APIs stayed on JSON while config files drifted toward TOML and YAML.

Choosing, and converting

A reasonable rule: TOML for files people edit (app config, tool settings), JSON for data that moves between systems (APIs, storage). Many projects use both, generating JSON from a TOML source of truth.

The two map cleanly onto each other for most structures, so converting is straightforward, with one caveat: comments do not survive a round trip to JSON and back, because JSON has nowhere to put them. Native TOML dates also become strings once they pass through JSON. If you convert TOML to JSON for a build step and then back, expect to lose the annotations and re-type any date handling.

The JSON to TOML Converter converts in either direction in your browser, so nothing you paste leaves your machine. If your config lives in YAML instead, see YAML to JSON and back, and for cleaning up the JSON side specifically, the pretty print vs minify JSON guide is a useful companion.