Remove JSON comments from settings files

guillermooo 13 years ago updated by rsp 12 years ago 10
JSON should not allow comments in files. (Maybe this has been fixed already.)
This is why JSON is a bad definition language. I was just reading a Stack Overflow response about why JSON needs comments vs why it doesn't.

It's lovely to use but comments would (in some ways) help.
Python's json module wouldn't work with comments, so that's a big drawback. I agree comments are useful sometimes.
Until there is a nice GUI for setting preferences i guess comments in JSON are badly needed to explain all the different settings. It's not valid, but then again maybe it isn't JSON but a Javascript object (which does allows comments) ;)
I'm generally against adding GUI layers to Sublime, but I suppose this will be a common request. Maybe better docs would suffice to clarify each option's purpose.
It isn't a JavaScript object, because it cannot parse things like:
font_size: 12
It would be nice if it could, though.

What is seems to be is just JSON+comments but there is no reason for it to be in any format - it doesn't have to be valid JSON since that data doesn't need to be passed to anything other than Sublime Text.

In fact, since Sublime is written in Python, I am surprised that its config is not in YAML which is a clean, low on punctuation, data serialization format with Python-style syntactically significant indentation - see: http://en.wikipedia.org/wiki/YAML#Examples

In fact YAML is a superset of JSON, so Sublime Text could change the config files format to YAML without actually changing any of the config files themselves - maybe only changing // comments to #. :)
Keep the comments. (Docs in one place: the comments! The online project docs get outdated too quickly right now). Just call it a Javascript object instead of JSON.
If you must, run it through a pre-parser to strip comments before passing it to a JSON interpreter.
+1 and while we're at it, make quoting of object keys optional so the config parser wouldn't break on things like font_size: 12. That would be really nice.
Douglas Crockford words on the matter: https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr

Don't use comments in Json - or make them as a special key (eg. "_doc_":"your doc here")
Actually, the Douglas Crockford words that you quote are:
"Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser." [emphasis added]
So indeed Douglas Crockford recommends using comments in JSON configuration files but removing them before feeding it to the JSON parser, which is exactly what Sublime Text seems to be doing.

Now, I know that just because Douglas Crockford says how to use comments in JSON, it doesn't necessarily mean we must do it, but from reading your comment one might conclude that he has said exactly the opposite thing, which he hasn't.

As for me, I found this thread when I noticed that Sublime Text removes comments from my user preferences every time I change the font size or color scheme via the user interface or key bindings (like hitting Control+Minus) which I found highly annoying, and looking for a solution I found this thread instead.

I find it surprising that anyone would not want comments in the config files - for those I can only recommend: pipe it through grep -v '^\s*//' and get over it.