DEV Community

Discussion on: YAML vs. XML vs. JSON for Configuration

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

YAML, for a couple of very specific reasons:

  • It's reasonably concise. YAML doesn't waste huge amounts of space like XML usually does, it just uses exactly what's needed for structure and nothing more.
  • It allows comments. This is honestly one of my biggest complaints about JSON. On any reasonable system, your configuration should be properly documented, and that's harder to do without comments. Also, lack of support for comments makes it hard to temporarily disable a segment of the configuration.
  • It's not picky about quotes. Another complaint about JSON specifically, and some other config formats generically. I hate having to remember what type of quotation marks to use around values that need quoted, and for that matter whether or not values need quoted at all. YAML makes this dead simple.
  • In most implementations, it allows both full and partial reuse of segments of the configuration. This is a huge benefit when dealing with situations where you have to use essentially the same configuration for a bunch of things with minimal modification. YAML is a bit unique in that it's the only widespread config formats that lets you reuse the contents of a mapping while selectively changing only some keys.
Collapse
 
frankfont profile image
Frank Font

I'm using JSON these days just because most of my day to day coding is js/ts and the native integration of JSON with these projects is seamless and clear.

I also agree with everything Austin S. Hemmelgarn expressed so clearly above.

Mostly I don't choose XML anymore. It was my go-to until just a few years ago.

One format you didn't mention that is still around in a big way for shell scripts is simple Key=Value files. They are not going away soon enough. :)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

I have to disagree about quotes (standard should always be double quotes, and if single quote only for chars), and there is problem about Yes, No, true, false, date-time.

It is just some JSON over-done.

Otherwise, you are right about circular reference.

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

I'll agree on the point about handling of booleans, it gets a bit tricky at times in YAML, especially since some tools that use YAML accept other things for booleans (for example, lots of stuff accpets on and off as booleans in it's configuration when using YAML).

As far as quotes though, I would argue that it's actually better even for those who are pedantic about quoting that YAML doesn't care. Yes, you might run into existing YAM that quotes things differently than you expect, but OTOH you can use whichever quoting (including none at all in many cases) you prefer and it just works (provided it's not crazy stuff like Lua's multiline string format or Python's triple quotes). If you want to use double quotes for everything, nothing is preventing you from doing that, but for those of us who don't want to have to hit shift dozens of extra times, it's still accommodating.

Collapse
 
missamarakay profile image
Amara Graham

Thank you for your detailed response!

Comments are key for what we are working on right now. Our configuration files are enormous and if we take away comments it becomes confusing and we can't ship with optional segments disabled.

I know some people love to hate YAML, so as we are building out our products I want to make sure we are making informed decisions about why we choose YAML, or any other config format for that matter.

Collapse
 
ghost profile image
Ghost

Austin got all my points, in special about comments, he didn't express all the hate and loathe that XML deserve, I really "dislike" it with the intensity of a thousand suns. Is basically a machine that converts simple, clear and useful data into a hot mess that you can only hope is somewhat well defined. I applaud his restraint tho, well done sir.

Collapse
 
missamarakay profile image
Amara Graham • Edited

"Into a hot mess you can only hope is somewhat well defined"

🤣

That hit me so hard it took me back into my IT days.