5 ms·
My biggest complaint with JSON is the lack of support for comments. For that reason, it's hard to take it seriously for human-maintained configurations.
by jameslk 8y ago
My biggest complaint with JSON is the lack of support for comments. For that reason, it's hard to take it seriously for human-maintained configurations.
- doktkrknr 8y agoI got hit by lack of comment support in go-yaml recently. https://github.com/go-yaml/yaml/issues/132 https://github.com/go-yaml/yaml/issues/132
- klodolph 8y agoComments and trailing commas. If those two features were added, I would use JSON for configuring everything. Naked keys would be a distant third. My conclusion is to use TOML or the protocol buffer text format. I've been slowly ripping out YAML support and converting configurations to TOML.
- furgooswft13 8y agoNot just trailing commas, but the need for commas at all when there is a newline right next to it has been a source of many stupid issues for me when less knowledgeable/experienced people edit json based conf files. Then there is floats without a leading zero. Missing colon after the key. And yea, naked keys. The need to wrap the entire file in { } or [ ] is just icing. Honestly I feel the most bare simple conf format of [first-word] [rest-of-line] is enough for many programs that end up using but never taking advantage of more powerful formats.
- GordonS 8y ago> but the need for commas at all when there is a newline right next to it JSON is often minified though - you're going to need something to use as a delimiter
- jampekka 8y agoA newline character is just as minimal as any other ASCII delimiter.
- furgooswft13 8y agoI would hope minified JSON is not being used for conf files.
- wolfgang42 8y agoNewline and comma are both 1 byte. You could specify that either is acceptable. Actually, I think you could leave out the delimiter altogether and still be syntactically unambiguous, since quotes are required around keys: "key1":"value1""key2":2.75"key3":true"key4":"whatever" though this looks terrible and there's probably some edge case I've forgotten. (Also it misses the point of JSON in that it's no longer valid JS. I don't know whether that's important anymore since you should be calling JSON.parse() not eval() anyway.)
- furgooswft13 8y ago> you should be calling JSON.parse() not eval() The one major reason I could see to use "JSON" as a conf file is in trusted node.js apps because you can then easily embed functions and logic in them if you need more advanced/customizable configurations. And you can do it with full syntax highlighting in your editor. And comments, and trailing commas, and naked keys. Of course this is no longer JSON, it's straight up Javascript config files. But it has come in handy a few times when I want to override standard behavior on a per config basis, and most of the file is still just plain key: val
- dilap 8y ago"comment": "blah" is one hack. it's a shame json doesn't support them though. oh well. would be nice to restart the universe and get all this right next time. :-)