A human-readable ASCII configuration/serialization file format with comments and parsers for multiple languages that preserve order and comments

53 views Asked by At

My project uses .py files as config files right now. They are very hard to modify from scripts, we had to write our own simplified-python parser. The config files are complex, lots of dicts and we need to modify them a lot, sometimes with scripts.

I would like to move the project to configuration files that support comments (so pure JSON is out) and ideally a format that is supported by more than just Python with existing simple parsers. Ideally something that doesn't look too different from JSON/Python dicts. The project uses a lot of dicts/hashes to organize the configuration.

It is surprisingly hard to find a file format for this use case!

Candidates:

  • JSON5: would be perfect, but there only one library to parse/edit/write that preserves the comments and it's in Javascript which the backend people don't use: https://github.com/noahsug/json5-writer and it's in Javascript.

  • HJSON, looks perfect but cannot find a library the supports preserving comments / writing back.

  • YAML: only comment-preserving library is ruaml, and only Python. Would be OK, but looks quite different from JSON/Python and would be nice to have at least one other language supported.

  • XML sucks, INI doesn't have dicts/hashes, eno-lang looks weird, TOML has no comment-preserving parser and dicts there look weird with the dot notation.

A good overview of the topic is here but it's from 2016: https://kevin.burke.dev/kevin/more-comment-preserving-configuration-parsers/

0

There are 0 answers