3 ms·
It's a real shame JSON doesn't have 3 and 4, because it would be so easy and it's otherwise pretty much perfect imo. No ambiguity, every value type can be ident
by brundolf 5y ago
It's a real shame JSON doesn't have 3 and 4, because it would be so easy and it's otherwise pretty much perfect imo. No ambiguity, every value type can be identified by its first character, clean and reasonably minimal syntax.
- plusmax1 5y agowell there are json alternatives which fit this bill, such as HJSON. https://hjson.github.io/ https://hjson.github.io/ might not be as "common" but it has good implementations for many languages.
- MichaelMoser123 5y agoyou could allow python like comments and strip them with a regular expression substitution before parsing. Something like this. (it strips all the lines that start with whitespace, followed by #, followed by anything until the end of the line) cat cfg.json | sed -e 's/\s*#.*$//g' | jq . Allowing multiple lines is more complicated, can't do that with regex alone.
- brundolf 5y agoThere are lots of ways to implement it. The problem is that one of JSON's strengths is its ubiquity: every language under the sun has half a dozen different battle-tested parsers for it. Clients and servers and everything in-between have first-class support out of the box. You can even paste it directly into JavaScript as valid code. If anybody short of a standards body tries to expand the spec, you lose out on most of that.
- MichaelMoser123 5y agoi think you can possibly define how you want to use json for a configuration file; json by itself is not much more than javascript objects/maps, defined as a data format. I frankly don't think that you need to be too pious about standard compliance if dealing with a cofiguration format for your application.
- bschwindHN 5y agoJSON5 is nice. I use it for all our configuration files at work after evaluating a large list of configuration file formats. I've never really run into any frustration using it, whereas YAML, TOML, and others drive me crazy when I need to represent nested structures or arrays. https://json5.org/ https://json5.org/
- FrancoisBosun 5y agoWhat about a key named “_comment”, or something similar? Of course, the underlying software must ignore unknown keys, so it’s not a full win anyway.
- nicklarsennz 5y agoThat might help for a general comment, but not for a comment on a specific part of the structure.