Earlier quoted context omitted.
At work we're currently expanding to another country. Which means that many services now need a country label etc., which is fun when you're adding "no" to all our existing services. Luckily it's quick to catch, but man... why?
Yeah, I'm pretty sure there are exactly two substantive problems with JSON for (static) configuration file use cases, which are comments and multiline strings (especially with sane handling of indentation). YAML fixes these, but it adds so much complexity in the process including such a predictable footgun of unquoted strings (the no/false problem is particularly glaring/absurd, but it's also easy to forget to quote…
// comments!
({
no_quotes: [1, 2, (() => /* code! */)()],
...
})
Or, let the whole thing be a function. Then your config can have parameters, maybe mapped from environment variables or something. ({foo, bar, ...kwargs}) => ({
datacenter: foo === 'old' ? 'useast1' : 'uswest',
...
})
Can do as Crockford says, and write in the JSON subset of Javascript, but with comments, and convert it to JSON by running it through a JS minifier. I think you need parens around the object, though, or else it looks like a code block (boooo...): ({
// This is very much like JSON
"foo": [1, 2, "bar"]
})
Python also has JSON-like syntax, so you could use config.py: {
'foo': [1, 2, 'bar']
}
That would require a wrapper script. Or, you can have the self-contained convention: import json
import sys
# Yay, comments!
json.dump({
# more comments!
'foo': [1, 2, 'bar']
}, sys.stdout)