6 ms·
> In contrast, JSON is super intuitive and basically self documenting. The only real quirks are that you need to use double quotes, and objects can't have a tra
by mschuster91 8y ago
> In contrast, JSON is super intuitive and basically self documenting. The only real quirks are that you need to use double quotes, and objects can't have a trailing comma.
I'd expand the list of quirks... JSON lacks comments (both line-level and block level). Fine for data transport but super super bad for configuration files.
- lostctown 8y agoThis hits home. Every time I've ever had to make the decision I've chosen yaml, for exactly this reason. Funny how the seemingly small things can be absolute show stoppers when it comes to making decisions in production.
- twodave 8y agoIn our JSON config files we do: { "ConfigKeyComment": "This is for blah blah blah", "ConfigKey": "Foo" } Obviously this wouldn't work in all cases (you're putting more work on your parser to interpret unused keys basically), but if we're talking config files specifically, I see this as an acceptable approach since there's little chance you'll be parsing such files more than once each (plus, writing a simple tool to strip the comments out would be very trivial).
- biztos 8y agoI've tried something similar but found it way too painful if the comments need to be long... # Never enable this config, because if you do the space-time # continuum will collapse into itself and the cloud servers # will disappear in a puff of steam. However, if you really # must enable it, remember that it's boolean and go read # TICKET-8675309 for the extensive list of side effects. TurboFactorRenoberation = false ...so people just end up writing stuff like: { "ConfigKeyComment": "TICKET-8675309", "ConfigKey": "TurboFactorRenoberation", "ConfigVal": false } [edit]: formatting
- mschuster91 8y agoThat's not JSON anymore, that's pretty much enough to be considered a unique DSL. Scary that this is more or less required.
- zaphar 8y agoAlmost all applications evolve their config files into unique DSLs over time. They may choose a generic serialization for the DSL's AST but it will end up being an underspecified application specific DSL regardless.
- lostctown 8y agoInteresting approach. Maybe I'm lazy but avoiding increasing cost to commenting is one of the few absolutes I abide by. Often I find myself tired after a long stretch of code, trying to convince myself that's it's understandable on it's own. This is one of those systematic rules I have to enforce to shutdown my lazy lizard brain. edit: But I can see how highly structured comments could actually come in handy as well for viewing configs in a gui
- Zamicol 8y ago>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. -Douglas Crockford, creator of JSON There is no issue using JSON with comments for a config file.
- always_good 8y agoOr pipe through json5 which has other conveniences one might want like trailing commas.
- Zamicol 8y agoI love json5, but it's not always an option.
- always_good 8y agoYes, but ITT we're talking about someone apparently having the option to pick which format they're using for config, and they'd use JSON if it wasn't for one dealbreaker.
- ngrilly 8y agoYes, except for the fact that ECMAScript has a syntax for comments, but not JSON. Standards matter.
- artpepper2 8y agoBlurg, now every tooling pipeline that uses JSON needs to include a JSMin step...
- Zamicol 8y agoIf you're making comments for yourself in config files you control: /\/\/.*/gm https://regexr.com/3rbgb https://regexr.com/3rbgb
- tlb 8y agoJSON5 supports comments, and is only slightly more complex than JSON. https://json5.org/ https://json5.org/
- outworlder 8y agoMost parsers will not support JSON5.
- nostalgeek 8y agoMore like browsers can de-serialize JSON5 natively. writing a JSON5 parser is not difficult. It's just not part of most std libs in most languages, but I would argue that most std libs don't parse YAML either. JSON5 is a good compromise.
- tlb 8y agoNeither Chrome nor Firefox's JSON.parse accept JSON5. I'm not sure what browser API you mean. For example, JSON.parse(`{"foo":"bar",}`) throws a syntax error.
- nostalgeek 8y ago> Neither Chrome nor Firefox's JSON.parse accept JSON5. I'm not sure what browser API you mean. This is a typo, I meant "can't" not "can". Off course browsers don't support JSON5 or my message makes no sense whatsoever.
- saghm 8y agoThe barrier here would be whether there's support in enough implementations to feel safe using it in the wild, which I'm guessing will take a while at the very least.
- tajen 8y agoWhat’s incredible here is that we’re not at the beginning of programming, when we built temporary languages that ended up becoming forgotten. Web may be a final form of IT, Angular may be the « right », the final, the perfect way to build applications even in 50 years, just like HTML has become the final way to build websites for the last 25 years, JSON may make legacy, and my grandson might even struggle with parsers that still use JSON instead of this new tech called JSON5...
- gaius 8y agoJSON lacks comments (both line-level and block level) “_comment”: “blah blah blah”, Simples
- lomnakkus 8y agoThat doesn't work if you use a strict parser where superfluous fields are an error. It's quite rare, but there are good use cases for that kind of strictness.
- Carpetsmoker 8y agoThis is ugly.
- sho 8y ago> lacks comments [..] super super bad for configuration files Not that that matters when applications take it upon themselves to re-save the config file in some kind of normalisation effort. Bye-bye comments, hope they're checked in somewhere. I'm lookin' at you, kubernetes...