4 ms·
What do people expect out of json comments? Should they be round trippable? Returned as part of data or out of band as extra metadata? Do we need to make them r
by sour-taste 2y ago
What do people expect out of json comments? Should they be round trippable? Returned as part of data or out of band as extra metadata? Do we need to make them round trippable to old parsers that don't understand comments? So many interesting questions for one of the most used formats in the world!
- Asraelite 2y agoNo. Neither. No. It's the same as whitespace. You don't expect it to be round-trippable, it's just to make the source file easier to read. Likewise I would interpret any expectation of the preservation of comments the same as an expectation of the preservation of whitespace: weird, unreasonable, and probably arising from a misunderstanding of how JSON works.
- jon_richards 2y agoYeah. A round-trippable comment is just another text field. Leave that to the application. It’s unfortunate how many APIs are documented with a single json example, but annotating them with comments (and maybe types?) would help immensely.
- eadmund 2y agoIf an application stores its configuration in JSON, and I edit it by hand and leave a commented ‘// I did this because the other way was broken,’ then I open the application and change the configuration there … then I expect my comment to survive. XML preserved whitespace, too! I dislike XML intensely, but there was a method to its madness. There’s a method to JSON, too: simplicity and usability. You start adding things to JSON, you lose that.