4 ms·
So, besides not playing nice with other parsers, I wonder if there's much harm in adding `//` and `/*` style comments. For example, if you use a specific struct
by spicybright 6y ago
So, besides not playing nice with other parsers, I wonder if there's much harm in adding `//` and `/*` style comments. For example, if you use a specific structure of json for a config file in project you make, you could add comment support to your parser.
I also wonder how much of a pain it would be to add comments to json, like a json v2
- IshKebab 6y agoIt exists: https://json5.org/ https://json5.org/ However I think it goes too far. E.g. why support single quoted strings? That just makes parsing harder. I prefer the format Microsoft uses in VSCode and Typescript - JSONC. It's just JSON but with trailing commas and comments. The downside is it isn't obvious when something is JSON and when it is JSONC because they use the same extension.
- crehn 6y ago> why support single quoted strings? That just makes parsing harder. And something that a lot of language designs ignore: it makes writing harder and unnecessarily contentious. People will use them inconsistently, which has the usual effects any inconsistency has on cognitive load: causes others to question why/how/where.
- olliej 6y agoWhile there are many things that make any change to json changes challenging, single vs. double quote really isn’t a problem, the JSC JSON parser supprots them at an implementation level as it is also used for jsonp insanity, it’s just that in pure JSON mode (eg JSON.parse) it doesn’t allow single quotes or a few other similar “real” js language features it supports for the sake of jsonp
- reificator 6y agoComments in JSON are easy. You just strip them out before sending to a strict parser. Some parsers even support them out of the box. In fact they're so easy they were already in JSON, and then later removed. > I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. ~Douglas Crockford
- polymonster 6y agoI’m using this json like data format.. supporting json and json5 plus a few more features, including comments https://github.com/polymonster/jsn https://github.com/polymonster/jsn