4 ms·
JSON is great, but I surely wish it supported comments. That's the nature of its failings: too minimal.
by adamc 4y ago
JSON is great, but I surely wish it supported comments. That's the nature of its failings: too minimal.
- beached_whale 4y agoLuckily a good number of parsers support extensions to JSON like comments and trailing comma's.
- wongarsu 4y agoThat depends on what you want it to be. For a data interchange format, having no comments is arguably a strength. For a config file format, having no comments is a big weakness.
- sgtnoodle 4y agoMany people use text format protobufs for config. It vaguely resembles yaml, and the schema is enforced by virtue of requiring a message definition in order to parse it.
- hot_gril 4y agoJust do { "someSetting": true "comment": "TODO change to false when ready" } Though really text-based protobufs are better for config.
- sixbrx 4y agoProblems are that some tools will rewrite the file and reorder the "comment" away from what it's meant to comment on. Also might complain the "comment" item isn't expected there. I seem to remember package.json suffering from both of these under the control of npm.
- hot_gril 4y agoYeah it's definitely a limited solution, and I prefer that JSON be kept simple that way. Many package.json-adjacent configs like the Babel stuff can be in .js files, giving you comments and everything.
- keneda7 4y agoThis always bothered me. A coworker once suggested using fields ending in 'notes' to put in comments but I never really warmed up to that.
- rqtwteye 4y agoI have heard that too but it’s just a terrible idea.
- PurpleRamen 4y agoComments are simple to parse, but preserving them on the dump is complex. I guess they were sacrificed for the simplicity.
- rqtwteye 4y agoThat’s a good point. It would be hard to read the JSON, modify it and then write back with comments. But you still should have the option to at least ignore them while reading. That would make JSON config files so much better to work with.
- Marazan 4y agoThey were excluded so people wouldn't use them to insert meta-processing instructions into the JSON doc. In reality people insert those meta-processing instructions in other ways.
- maxloh 4y agoYou can use JSONC, which is JOSN with C style comments.