back

by jasonpeacock·6y ago·view on hn ↗
Of configuration file formats, TOML is my favorite. It hits the right balance of power and simplicity, it's been able to handle my needs with minimal effort and fuss.

I tried Python's INI for configuration, but it was both too simple and too complex at the same time, very frustrating.

YAML is a nightmare, the formatting is way too easy to get wrong and accidentally break your configuration.

JSON is too strict/simple. You can't even have trailing commas in a list!

4 comments
I recently wrote a TOML parser in Idris2. It's a cool language, but has some quirks. For me, it's that it's just a simple KV store with some sugar (that's nice!) but it also means that a lot of information is lost forever in parsing. For example, these two documents are strictly identical:

    [info]
    name = { first="bob", last="jones" }
and

    info.name.first="bob"
    info.name.first="jones"
This can be seen as a positive (it's a really simple document) or a negative (it's hard to machine-generate nice TOML, and it's easy to think there's more to the structure of a written document than there is).
Can you expand on the negatives? I don't think I understand what you mean.
I believe the main negative he is referring to is that there is no canonical representation for a given document. The input file can be structured to share common keys (in the example above it's `info`) or not. Since both inputs are parsed into the same value it means that writing a printer is harder: you now have the choice between different output representations.

As a comparison, there's not much choice when serializing to JSON - the only variation is around whitespace. When serializing TOML you need more insight to decide what's the best representation for a human. A contributing factor to this issue is that TOML is mostly used for configuration files, so it often matters that the output is readable.

JSON is too strict/simple

This is why I like JSON!

I have seen the horrors of XSLT and I’m never going back.

IMO it kind of sucks that you're not able to add comments to JSON easily.

In TOML (or YAML) it's just as easy as prepending it with # at the beginning of the line.

I've seen folks add comments to json... as data

  {"comment":"hi mom", ...}
> add comments to JSON easily

Simple, write comments in Morse code using spaces and tabs.

There are a few projects with a similar feel as json yet allowing nice to haves like comments and trailing commas:

* json5

* HCl

* hjson (now unmaintained)

> hjson (now unmaintained)

Which is quite sad, as I thought that it was the best one (if memory serves)..

I tried the go and rust implementations and they each had subtly broken behavior for things like leading slashes in key names or trailing commas. I want something much more strict than "human" json. Maybe a "lizard person" object notation would fit me better.
For a typescript project, after going from .ini and .toml I figured I'd just write config file in typescript. You'd get all the type hinting, auto completion and error checks.

I never liked that anything I pulled from a config file was never checked by typescript, so I just went simple with TS itself.

I understand if I use another language within the same project, it'll be a problem but until then this can't be beaten.