Per Douglas Crockford, the creator of JSON, comments were an anti-feature:
> 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/20120507093915/https://plus.goog...
Discussion on the post (2012):
* https://news.ycombinator.com/item?id=3912149
Remember: JSON was designed primarily as a data exchange format between computers.
I think this is a bit of 'over reach' in what JSON was intended to do, so it's perhaps not surprising that there may be some things 'lacking' for that purpose.
They're really bad for a data interchange format though, because people inevitably start putting important data in them and you end up with two different ways to write strings, one of which isn't supported by every parsing library.
Thus each discussion of JSON ends up being two groups talking past each other, the people using it as a configuration format who lament the lack of comments, and the people using it as a data interchange format who celebrate it.
The solution: since it's too late to add comments now, don't use JSON as a configuration format.
Any feature or tool can be abused and misused. Comments are useful for configuration files, period.
For data interchange formats comments do presents major problem.
I don't have a single competitor to recommend, but JSON5, TOML, JSONC (mentioned in a sister comment), or something else along those lines might be better. I'd probably just go with whichever of those is popular in your community.
(and yaml is TERRIBLE)
For me, readability is king both for myself and because I sometimes want non-developers to be able to hand-edit files.
Any curly brace format is a non-starter. Too much clutter, too easy to create invalid files that aren't obviously invalid at a glance.
Significant white space does have the advantage of meaning exactly what it appears to mean and being intuitively understandable to most people.
The core project implements a JavaScript module [1] but it looks like there are also experimental JSON5 libraries for Go [2], Python [3], Ruby [4], and Rust [5].
[1]: https://www.npmjs.com/package/json5
[2]: https://github.com/yosuke-furukawa/json5
[3]: https://pypi.org/project/json5/
[4]: https://github.com/bartoszkopinski/json5
I noticed that JSON5 doesn’t include a Date type. There have been discussions about this in both the JavaScript [6] and spec [7] repos but with no resolution yet.
<script src="//unpkg.com/json5/dist/index.min.js"></script>
to every HTML page as extra JavaScript instead of a native browser implementation.The litany is not short and I'm sure I've overlooked a couple.
But if you add too many features, it may end up like XML.
For numeric types, if you handle integer larger than 2 billions or floating numbers where the precision is critical (that's where json fails), these can and should be represented as string. I don't think there is any common format that guarantees large numbers and/or arbitrary precision to be encoded and decoded properly across languages and platforms.
Perhaps CDDL:
This allows trailing commas and comments. This can also reads strict json of course. Libraries are available for all popular languages.