Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

JSON has an advantage of not having significant whitespace: a bit more verbose with the { and [, but I'd argue it is more robust for complex configuration.

YAML feels to me like the creation of a person who has never fought with a makefile that imported another makefile that had an extra tab on line 9432: not quite true hell, but a few hours of trying to figure out WHY things aren't working right you would be hard pressed to tell the difference.



How is "no whitespace" an advantage for a human readable file format? You could write JSON with zero whitespace, but you wouldn't because whitespace is absolutely necessary for human comprehensibility.


Because humans make stupid accidental mistakes.

YAML says there's a world of difference between

    - flag1
    - option2
and

    -flag1
    -option2
but for a human who just wants their thing to work, that's inscrutable, but in JSON, they become

    [
        "flag1", 
        "config2"
    ]
and

    "-flag1 -config2"
respectively.

Personally, live python as config is my preference, followed by YAML because comments, but YAML isn't perfect.

If the options are right next to each other it's clear there's a misalignment:

    - option1
     -option2
won't work, but

     - option1
# if there is a huge explanatory

# multi-line comment

# as is sometimes seen in config

# files, sometimes it can be hard

# to see the misalignment.

      - option2


As @rockostrich and @fragmede pointed out, I'm talking about whitespace having parsing impact ("significant whitespace"), not just any whitespace. The fact that extra spaces changes the structure of the output seems like a total minefield to me, unless your config is being machine generated (in which case there are many more robust formats to choose).


No significant whitespace you say? Take a peek at this: https://paste.ofcode.org/n9q3dnDcPDK5KLex54z6uw


By "significant", fomojola meant whitespace does not affect parsing. That JSON you linked to could be minified into a single line with 0 whitespace and still be parsed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: