4 ms·
> > Single (//...) and multi-line (/.../) comments are allowed. We can now have different parsers have pragmas that specify different behaviour depending on wh
by throw0101a 3y ago
> > Single (//...) and multi-line (/.../) comments are allowed.
We can now have different parsers have pragmas that specify different behaviour depending on whether those pragmas are recognized or not.
In case anyone was wondering, the history is that comments were considered an anti-feature by Douglas Crockford, the creator of JSON:
> I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't.
> 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.
* https://web.archive.org/web/20150105080225/https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaGSr https://web.archive.org/web/20150105080225/https://plus.goog...
* https://en.wikipedia.org/wiki/Douglas_Crockford https://en.wikipedia.org/wiki/Douglas_Crockford
- arp242 3y agoAnd for a data interchange format this is also 100% reasonable. The problem is that people have started using JSON for configuration files and the like, which IMHO has always been – and continues to be – the wrong tool for the job.
- hgsgm 3y agoHow does that relate? Your config parser can disregard commments.
- arp242 3y agoYes, but JSON was never intended for that use case – the feature set isn't geared towards it.
- mikepurvis 3y agoI think the point is that your config parser should be using yaml or toml, though in fairness neither of those existed in the early 2000s when JSON was being developed/discovered/adopted— the 800lb gorilla in that space at the time was XML. And XML remained dominant for a long time— for example, the original Google Maps from 2005 received its server responses as XML blobs, and API v2 even exposed the relevant parsing functionality as the GXml JavaScript class. By around 2007, it was all JSONp I think, and GXml was deprecated and removed in API v3 and v4 respectively.
- deepsun 3y agoWhat comments? JSON doesn't have any. And editor will rightfully mark them as errors.
- anentropic 3y agothat's the JSON5 support
- deepsun 3y agoThat's my point. Parent says that config parser can disregard comments. Why would it need to disregard comments if it was json5?
- deepsun 3y agoLet's add parsing directives then.
- hbrn 3y ago> Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser. Every problem can be solved by introducing a build step, except for the problem of having too many build steps.
- deleted 3y ago[deleted]