5 ms·
I'll give my opinion as someone who has to choose among JSON, XML, TOML, and YAML about two years ago for a new project. Whatever I chose had to be easy for end
by avsteele 5y ago
I'll give my opinion as someone who has to choose among JSON, XML, TOML, and YAML about two years ago for a new project. Whatever I chose had to be easy for end-users who don't know the specification to to understand later.
Here were my thoughts on the options.
JSON - No comments -> impossible
XML - Unreadable
YAML - 2nd place. Meaningful indentation also made me worried someone was going to not understand why their file didn't work. The lack of quotes around strings was frustrating.
TOML - 1st place. Simpler than YAML to read & parse. It truly seems 'obvious' like the name says.
I haven't encountered any situations where I wish I had more than TOML offers.
- signal11 5y agoThere’s properties files too, but TOML is my “format of choice” as well for a bunch of use-cases where human readability is important. More people should give it a try. Very reminiscent of old Windows INI files and Java properties.
- Gigachad 5y agoJSON with comments would be ideal.
- KronisLV 5y agoIn that case, you might want to have a look at JSON5: https://json5.org/ https://json5.org/ It is pretty niche, but attempts to improve upon JSON in a multitude of ways, one of which is the support for comments: https://spec.json5.org/#comments https://spec.json5.org/#comments
- emn13 5y agoWhich is why many parsers support that. I'm positive you'll find one that does so in pretty much every environment.
- cozzyd 5y agoThe libconfig format is fairly close to that, and it's great! http://hyperrealm.github.io/libconfig/libconfig_manual.html#Configuration-Files http://hyperrealm.github.io/libconfig/libconfig_manual.html#...
- benatkin 5y agoI disagree. TOML is terrible at handling nested data. Check this thread: https://news.ycombinator.com/item?id=17523194 https://news.ycombinator.com/item?id=17523194 I don't see Kubernetes switching to TOML anytime soon!
- mountainriver 5y agoAlso agree, I find toml way less readable than yaml for lots of data structures
- Aeolun 5y agoThere may be no nested data in his use case. There’s no single correct answer here.
- benatkin 5y agoToo YAGNI for me.
- avsteele 5y agoI have nesting up to three levels deep. I use inline tables^ for the many innermost (or other few-element) tables. It's never seemed excessively verbose. ^https://toml.io/en/v1.0.0#inline-table https://toml.io/en/v1.0.0#inline-table
- benatkin 5y agoA bit later you see [fruits.physical] Even XML doesn't make you repeat the higher level keys!
- encryptluks2 5y agoI think the "right" choice is HCL
- deleted 5y ago[deleted]
- DethNinja 5y agoTOML is pretty good but it gets too verbose when you add bunch of arrays. All we need is to revise official JSON standard(ECMA 404) to include comments.
- benatkin 5y ago> All we need is to revise official JSON standard(ECMA 404) to include comments. That would be a step back for GitLab CI, GitHub Actions, Kubernetes, Google App Engine, and a bunch of other projects which use YAML and seldom encounter the Norway problem. https://hitchdev.com/strictyaml/why/implicit-typing-removed/ https://hitchdev.com/strictyaml/why/implicit-typing-removed/
- gray_-_wolf 5y agoAnd trailing commas. And unquoted keys.
- distortedsignal 5y agoWhy are unquoted keys so critical? I feel like one of the strengths of a DDL like JSON or XML is that it's easy to tell what the data (key-value pair or otherwise) is, while with YAML and others, understanding data-vs-structure can be challenging.
- Aeolun 5y agoMostly so copy between JS and JSON isn’t such a PITA. It’s not essential, but if we’re already changing the format we might as well?
- errcorrectcode 5y agoTOML can handle nested data at the application level by using entity reference token semantics. It does need an XPath traversal and search query format for application use and data references.
- benatkin 5y agoShoehorning.
- Andrew_nenakhov 5y agoThe unreadability of XML is grossly exaggerated.
- sigzero 5y agoI agree. I have never really had a problem reading XML myself.
- mindcrime 5y agoI guess it's just matter of personal taste, but I don't see how XML is any more "unreadable" than any of the other options mention here.
- speed_spread 5y agoTOML can't decide if it's a super INI file or a JSON cousin. You can represent the same information using two completely different representations and you can mix both styles in the same document. Manually navigating and editing values is error prone and hard to automate.