3 ms·
I usually just add my comment as an additional field called _comment or something like that
by justmedep 2y ago
I usually just add my comment as an additional field called _comment or something like that
- hn_throwaway_99 2y agoExactly, and that's a crappier workaround. E.g. in lots of places you can't just have willy-nilly, anything-goes key names. An example I think every Node developer can commiserate with is that there isn't really a great way to add comments in the dependencies or devDependencies section in package.json, because those keys need to refer to module names, and that's where I most often want to use comments in package.json. I won't rehash all the details but just take a look at https://stackoverflow.com/questions/14221579/how-do-i-add-comments-to-package-json-for-npm-install https://stackoverflow.com/questions/14221579/how-do-i-add-co... . Unfortunately none of the answers there are very good. In the past I've resorted to doing what https://stackoverflow.com/a/45815391/1075909 https://stackoverflow.com/a/45815391/1075909 does, but that ends up not working very well once you've got a long list of dependencies, because the comment for any particular dependency ends up being far from the entry that specifies the dependency (instead of the line above), so people end up not reading it or forget to update it if that becomes necessary. Yeah, I really, really hate that JSON doesn't have comments :)
- efitz 2y agoI have encountered many systems that explicitly disallow “unexpected” JSON elements and such an approach would fail. This is particularly common when using JSON around API-like use cases.
- thayne 2y agoSo how do you add a comment in the middle of an array?
- oneeyedpigeon 2y agoHow do you add a comment in the middle of a keyword in JavaScript?
- jefftk 2y agoI often want to comment individual array values to give more context or describe provenance. I don't think I've ever wanted to add a comment in the middle of a keyword.
- CharlieDigital 2y agoThese two are not remotely the same thing. You can have an array declared on multiple lines and add a comment to specific values. Or even inline with the value /* */.