3 ms·
If the config is in the form of: { "file": "/etc/foo", "daemon": true } Couldn't you add comments like so, all within the existing spe
by IgorPartola 9y ago
If the config is in the form of:
{
"file": "/etc/foo",
"daemon": true
}
Couldn't you add comments like so, all within the existing spec?
{
"file": "/etc/foo",
"_daemon_comment": "default is false",
"daemon": true
}
- krapp 9y agoThe problem is that's not really a comment, it's a string which needs to be evaluated as data, wasting resources while never being used. In any sane language, comments are simply ignored by the parser or compiler. Because Douglas Crockford didn't want people abusing comments in JSON by turning them into parsing directives, JSON doesn't allow using comments at all, even correctly, so everyone is left abusing JSON itself with workarounds that are objectively worse than just having comments.
- querulous 9y agoif you're using json as a config file you can choose a json parser that supports comments. there are a number of them
- zackelan 9y agoAt that point you're not writing JSON though. Once you start bolting on non-standard bells and whistles, why not recognize that JSON was never meant to be used for config files, and switch to something that was, like TOML [0]? 0: https://npf.io/2014/08/intro-to-toml/ https://npf.io/2014/08/intro-to-toml/
- zwerdlds 9y agoAdditionally, working against a json schema with additional properties false would cause a validation failure.