3 ms·
VS Code uses JSON with comments for config files. [1] Technically, this is not JSON. You won't be able to use a standard JSON parser without stripping comments
by skybrian 8y ago
VS Code uses JSON with comments for config files. [1]
Technically, this is not JSON. You won't be able to use a standard JSON parser without stripping comments first. But you can use a simple, JSON-like language with comments for config.
[1] https://code.visualstudio.com/docs/languages/json#_json-with-comments https://code.visualstudio.com/docs/languages/json#_json-with...
- EamonnMR 8y ago> you can use a simple, JSON-like language with comments for config. YAML can be employed as a simple JSON-like language with comments.
- crooked-v 8y ago> simple YAML is much, much more complicated than JSON.
- hk__2 8y ago> simple YAML is much, much more complicated than JSON. Quoting a single word from the parent’s sentence is misleading. The sentence "YAML can be employed as a simple JSON-like language with comments." is true because JSON is YAML, so you can parse a JSON file with #-comments using a YAML parser.
- skybrian 8y agoThe parser is not simple, though, and that's what counts.
- bdhess 8y agoMost YAML users don't need to look at the source for a YAML parser. I appreciate elegant simplicity, but I don't think parser complexity is the most important metric by which to judge a data interchange format.
- skybrian 8y agoIf you use a YAML parser to parse JSON-with-comments, it will accept many inputs that don't correspond to JSON-with-comments, and furthermore is likely to report syntax errors that don't make sense to a user who only knows JSON. So, this unnecessary parser complexity is a usability issue. You should use a parser for the config language you actually intend to support.
- spankalee 8y agoJSON5 is also a great alternative: https://json5.org/ https://json5.org/ Supports comments, trailing commas, single quotes, multi-line strings, and more number formats.
- nojvek 8y agoI really wished json5 would support optional commas as well. If you have a new line, no comma needed. So you can do [ 1 2 3 ] New lines used by humans, computers should do a good job as well.
- spankalee 8y agoThat's not a subset of JavaScript though.
- adamkruszewski 8y agoIt looks very like an s-expression. Maybe we should go back to Lisp for our data encoding? (and to our code when we are at it? ;))
- Sean1708 8y agoLike https://hjson.org/ https://hjson.org/?
- spiralx 8y agoWell you could use CSON, which uses CoffeeScript notation that allows for constructs such as: required: [ 'firstName' 'lastName' ] which is the same as: { "required": [ "firstName", "lastName" ] } in JSON :)
- craigds 8y agoSublime Text does too.