3 ms·
One annoyance with JSON as a config-file format is that you apparently can't put comments in it. At least not out-of-band comments: http://stackoverflow.com/qu
by mechanical_fish 15y ago
One annoyance with JSON as a config-file format is that you apparently can't put comments in it. At least not out-of-band comments:
http://stackoverflow.com/questions/244777/can-i-comment-a-json-file http://stackoverflow.com/questions/244777/can-i-comment-a-js...
You can put in in-band comments, by defining a JSON format that has a bunch of '_comment' keys sprinkled through it, but that's annoying because you've got to design that in, and decide which elements deserve comments and which don't, and that's just a big hairy yak which sits there daring you to shave it, practically begging you to do a bunch of YAGNI up-front design of the comment protocol, and then even when you're done you still have to fret about how those keys might get misinterpreted by clients from now until the end of time. Even human readers will have to intuit the the semantics of your '_comment' key ("oh, the computer never reads this, this is just for me!"), whereas humans generally recognize the significance of real, standard comment syntaxes like # or ;; or // or what have you.
Or you could use a JSON preprocessor that strips the comments, but that's a little trap that you build for yourself, because now your JSON is no longer universally-parseable by any language's JSON library. You could strip the comments at build time, but now your production JSON files on the server don't have the comments, and this is likely to be just where you need them - you put them there for the troubleshooter, who will find them at 3am when the server just crashed.
But I've sometimes used JSON for these things anyway. Life is too short for perfectionism, and it is a nice clean format. Almost too clean.
- d0mine 15y agoYou could try YAML as a superset of JSON with comments.
- mechanical_fish 15y agoIndeed. This is pretty much my plan for the future.
- njharman 15y ago> can't put comments in it. Exactly! With 25 years of sysadmin / devops / whatever kids call it these days, I can attest to the fact that config files are for comments/documentation. That they happen to also configure some software is a minor side-effect.