7 ms·
JSON parsers that can accept comments
- neallindsay 2y agoFor what it's worth, yaml is JSON that allows comments (and a bunch of other syntax).
- recursive 2y agoAnd ambiguity. It's too far in the other direction IMO.
- loevborg 2y agoTell that to the Norwegians!
- neallindsay 2y agono
- jbaber 2y agoTOML is one-to-one with JSON, except allow comments. I like JSON lines format where I can strip comment lines out.
- selectnull 2y agoJust say no to yaml
- teekert 2y agoI like yaml, easily readable by computers as well as humans (without any coding experience even). I don’t see the problem with it.
- davexunit 2y ago> easily readable by computers Have you ever written or tried to write a YAML parser?
- teytra 2y agoIt's already done, so no need.
- teekert 2y agoI will forever be aware of the pain of the developers of pyaml whenever I `import yaml` from now on. And even more grateful too.
- davexunit 2y agoIt's actually not easy for computers to read YAML. It's very difficult, especially when compared to JSON.
- teekert 2y agoMy computer has little problems with it! Ok, we're being pedantic, perhaps it depends on how much information you put in a Yaml file, I usually see it used for small config files.
- p1necone 2y agoAnd is so pedantic about whitespace that you need to specifically configure your editor to be able to retain your sanity while editing it, no thanks.
- dorfsmay 2y agoyaml is a superset of JSON, which means that any parser that expect yaml will happily consume JSON! Also JSON + comment that's JSON5.
- r3trohack3r 2y agoI used to do this frequently. Take a JSON file, add comments, and parse it as YAML. Then I discovered a handful of YAML parsers in various languages support code execution on parsing. Which basically killed YAML for me.
- neallindsay 2y agoIt's definitely no good for JSON that you don't write yourself. But that's not the JSON that you want to write comments into.
- kstrauser 2y agoI appreciate that Python makes you choose between a “full” parser and a safe one.
- jgalt212 2y agoAt least in Python, YAML parsers are orders of magnitude slower than JSON parsers.
- nasmorn 2y agoI switched out my app config to YAML which parses much slower and now my app starts exactly as fast as before. I don’t think anyone proposes switching to YAML for your API endpoints
- tengbretson 2y agoUsing YAML will make you a more spiritually advanced being because every time you copy and paste content into a yaml document it requires a prayer.
- Group_B 2y agoI want to blow my brains out every time there is a mysterious tab indent in my file
- Animats 2y agoWhat comment syntax does he propose? // /* ... */ # --
- recursive 2y agoHe didn't propose one. But given the "JS" part of the "JSON" acronym, probably only the first two are reasonable. But the point is, if you are in control of your own parser, you can just use any one of those.
- a3w 2y agoJSON is not JS, says Doug, too. Since he said "any new JSON should not new JS or ON in the name, since we claims it is not a javascript object notation, in the end. Perhaps since JS/ES is changing, and not everything is an object in every language that wants to deal with JSON?
- recursive 2y agoI don't exactly understand what you're talking about but RFC 8259 explicitly says JSON is "javascript object notation".
- deleted 2y ago[deleted]
- Animats 2y ago> probably only the first two are reasonable. Yet YAML, which is somewhat related to JSON, uses # This is a comment I'm neither pro-comment or anti-comment, but I'm all for standardized comment syntax to avoid parsing hell.
- xeckr 2y agoThat's basically a new standard. I like it, but getting all JSON parsers on board will be tricky if not impossible. Maybe it deserves its own name. How about JSONc (JAYSON-SEE)? Edit: I read the fine print on the page after posting this... Turns out that I'm not the first to come up with jsonc. The author just isn't a huge fan and wants JSON parsers to accept comments. Good luck with that!
- vampaz 2y agobut my user can't write a browser
- NegativeK 2y agoYou don't _have_ to enable Mallett's Law.
- anotheracc88 2y agoYou can also put JPEG binary data in RSS feeds, send a string of emojis for an SSL handshake and stick HTML 1.0 directly in a docker image. You can do those things. You can even write tools that accept those things.
- model-15-DAV 2y agoJSON as a data-format should not have comments. JSON as a file-format should allow comments. The problem is this conflation between the two.
- martin-adams 2y agoCan I confirm that the reason it's not preferred to have comments in data-formats is because it's to be machine read only and as such should be as efficient as possible and not contain information that wont be used? Seeing as I can only see the use case as a file format to be read/written by humans in the loop, then maybe the conversation should be about compiling the file format to a data format for compatibility outside of the user tooling.
- ur-whale 2y ago> is because it's to be machine read only Why did they bother making it text-only ASCII then ?
- DaiPlusPlus 2y ago> ASCII JSON is notable for making UTF-8 encoding a hard requirement. …which was pretty ballsy back in the mid-2000s. We were still fighting with Shift-JIS and Windows-1252. Excel didn’t add proper support for UTF-8 until depressingly recently.
- hinkley 2y agoLate 90’s I had to fix bugs in a shiftJIS implementation. And I couldn’t read a lick of Japanese. Still can’t. I don’t remember when I started pushing for utf-8 everywhere but it was “early” by most people’s standards, so I know what you mean. And one of the things that makes me dislike MySQL is that they have a field type called utf-8 that isn’t. And they didn’t fix it, they introduced a new type instead. So that footgun was still there for all to trigger. So mad.
- foldr 2y ago
- code-faster 2y agoAll you're doing is creating a new spec that's not JSON. JSON has no comments. Your spec does. Your parsers handle both specs. https://xkcd.com/927/ https://xkcd.com/927/ applies
- dorfsmay 2y agoAnother advantage of JSON5 over JSON is that extra comma at the end of a list is not an issue.
- vasilvv 2y agoIsn't this the problem that JSON5 (and probably other similar projects) is supposed to solve? Both JSON (as defined in the RFC) and JSON5 have a nice property of being well-defined, meaning that you can use different libraries in different languages on different platforms to parse them, and expect the same result. "JSON but parser behaves reasonably (as defined by the speaker)" does not have this property.
- donatj 2y agoJSON5 would be ok if that's all it did. They added so much additional unnecessary complication that it undermines the simplicity of JSON that makes it good.
- avmich 2y agohttp://seriot.ch/projects/parsing_json.html http://seriot.ch/projects/parsing_json.html "Despite the clarifications they bring, RFC 7159 and 8259 contain several approximations and leaves many details loosely specified."
- hinkley 2y agoNothing will probably ever top Markdown in my mind for bullshit specifications. And Gruber wouldn’t give Jeff Atwood permission to call his variant <something> Markdown, or it seems anybody else, so we ended up with CommonMark, and GFM. Json5 is good for JSON at rest, as others have mentioned already.
- dolmen 2y agohttps://json5.org/ https://json5.org/
- deleted 2y ago[deleted]
- sushidev 2y agoLol “If Douglas Crockford actually is your dad then please do not read this web site.”
- eclectic29 2y agoOne man’s extremely horrible mistake and look how the whole industry has been suffering for decades - countless articles debating the existence or absence of comments, new formats, new parsers, new ways of adding comments, post-processing, etc. What a pity!
- fullstackwife 2y agoand also life of LLMs would be so much easier, all the JSON content, so much missing context!
- pavlov 2y agoIt’s better than having to deal with the ad hoc out-of-band data formats that people would inevitably have stuffed into comments if given the opportunity. Remember how JavaScript used to reside inside a HTML comment?
- eclectic29 2y agoYes, but you expect much better from a seasoned engineer.
- samatman 2y agoDefinitely. It's important that every ad-hoc out-of-band data format look "like this" never // Like this Bad Things will surely befall us if we break the taboo.
- fkyoureadthedoc 2y agoWhy would a comment be required for this when they can just use a string property? YAML has comments, and they are not used by any DSL abomination that I'm aware of.
- takluyver 2y agoConda package recipes have a preprocessor using "selectors" in comments to conditionally exclude certain lines in a YAML file. Not that this is particularly more ugly than other YAML DSLs, but it has been used.
- koolala 2y agoWhats the comment syntax they want? I didn't see it on the Lua page. Is it not on the page? {"comment" : "This works everywhere doesn't it?"}
- ur-whale 2y agoWayyyyy before comments, the one thing I'd want to see JSON support is effing trailing commas.
- 3eb7988a1663 2y agoThis one unambiguously seems like a mistake. Is there any steel man argument for why an extra comma should not be acceptable? Save a byte over the network?
- a3w 2y agoEcmascript is changing JS. JSON is old and unchanging. Which is an advantage and a disadvantage.
- kstrauser 2y agoI think that’s literally the only argument for it. And if you use compression, now you have to waste an extra symbol on `”` in addition to `”,`, so even that’s debatable.
- hinkley 2y ago“ is already a symbol, but for formatted JSON it’s more likely to be “,\r and “\r
- kstrauser 2y agoI bet `: “` is more common than a lonely double quote, except at the end of a list of quoted values. Eh, who knows? But I’m skeptical that the omitted comma actually saves any space in common situations.
- nigeltao 2y agoYou might like JWCC, which literally stands for JSON With Commas and Comments. https://nigeltao.github.io/blog/2021/json-with-commas-comments.html https://nigeltao.github.io/blog/2021/json-with-commas-commen...
- smitty1e 2y ago{"comment":"This valid JSON document totally has a comment."}
- oneeyedpigeon 2y agochar str[] = "That's like saying this is a C comment";
- deleted 2y ago[deleted]
- smitty1e 2y agoPossibly not the optimal way to comment code, but sure.
- sgarrity 2y agoImagine if he was though...
- tomcam 2y agoWhy am I always the last to find out
- a3w 2y ago// or /* */ comments? Doug, please adopt me! As a file format, just use jsonc or json5, if you want to use comments.
- oneeyedpigeon 2y agoDo the people who think JSON should have comments also think the CSV format should have comments?
- Y-bar 2y agoFor my part they are for slightly different use cases. While I seldom see CSV files being used for things like configuration and markup, I often see JSON used. And a lot of times configuration choices require explanations. It's not a binary choice. I am more in favour of JSON comments than I am for CSV comments, but if I were to need them, I would probably use the Emacs style: https://github.com/emacsmirror/emacswiki.org/blob/34edac6f86f834ae01eacf695ca58ca4b04e9cfd/csv-mode.el#L202-L219 https://github.com/emacsmirror/emacswiki.org/blob/34edac6f86...
- dvh 2y agoIf JSON had comments, people would start putting data in comments (mostly annotations probably). What will be next? Allow apostrophes for strings? Add schemas so that parsing JSON is getting blocked by firewall rules? No thanks.
- jimmaswell 2y agoPeople are already putting comments in JSON, it just goes in a "comment" field. So now resources are wasted processing it as a property instead of ignoring it.
- eadmund 2y agoBy putting it in a "comment" field the comment survives round-tripping, which is a virtue rather than a vice.
- pizza234 2y agoAlready explained in other comments. Devs can put whatever they want in the comments; (third party) parsers won't need to change anything, because they still treats those "special" comments as regular.
- gwbas1c 2y ago> Douglas Crockford Is Not Your Dad No, he's your drunk uncle who sounds smart when you're young. When you learn to form opinions of your own, you realize that his opinions are worthless hot air. Many years ago I went to a session where he promoted asynchronous Javascript as the "one true way." In the Q&A, I pointed out that callbacks made code much harder to read and maintain compared to threaded code; and then asked if there was a cleaner way to do it. His answer was quite rude. A few years later, we got the "async" keyword, which solved the problem.
- cma 2y agoAs soon as you lose stack traces things become so much harder to debug
- Vekz 2y agoDeeply nested inline anonymous function callbacks are the anti pattern. Decoupled explicit named functions passed as callbacks are a significantly better developer experience and provide clearer stack traces. I never understood why this conversation didn't take the lexicon and instead the imo inferior `async` pattern got pushed hard.
- hombre_fatal 2y agoExtracting callbacks into separate functions is just more indirection. And they don't solve the core issue of async control flow that async/await solves, so it's not an alternative to async/await much less a superior one. A classic example is when you want to conditionally do something asynchronously like B() in this case. function process(id, callback) { A(id, (result) => { if (result === 3) { B(() => { C(result, callback); }); } else { C(result, callback); } }); } Versus: async function process(id) { const result = await A(id); if (result === 3) { await B(); } return C(result); } Add a couple more layers of this and the async/await function stays simple and flat, and the callback version grows significantly more complex and nested.
- 2y ago
- gmiller123456 2y agoEveryone already know which xkcd applies to this, right?
- user3939382 2y agoAren’t comments already part of JSON5?
- agumonkey 2y agoThat was fast https://mastodon.social/@technomancy@hey.hagelb.org/113618655641936913 https://mastodon.social/@technomancy@hey.hagelb.org/11361865...
- amatecha 2y agoYou probably want to link to this rather than mastodon.social's "external link confirmation" https://hey.hagelb.org/@technomancy/statuses/01JEKS1B4Q5NS3434Q34AVVZGW https://hey.hagelb.org/@technomancy/statuses/01JEKS1B4Q5NS34...
- donatj 2y agoMaybe be should have been though. Files shouldn't be labeled as compliant with a standard and then not be. Full stop. The standard that is JSON does not support comments. Don't call something JSON that isn't. Use one of the many existing JSON extensions or create a new standard. DO NOT however just adhoc crap like this suggests, that's a road to hell.
- easton 2y agoI need to send it to the author, but ASP.NET Core’s JSON configuration parser also does json + comments by default. Confuses the hell out of my colleagues and VSCode when I do it though :D https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-9.0#comments-in-appsettingsjson https://learn.microsoft.com/en-us/aspnet/core/fundamentals/c...
- pfannkuchen 2y agoThe title could be interpreted as body shaming Douglas Crockford.
- davexunit 2y agoI love the subdomain and am a technomancy fan, but personally I'm ambivalent towards comments in JSON because imo it's only for machines to write and only occasionally for humans to read when debugging. package.json, etc. are misusing a wire format for configuration. But I suppose the horse has left the stable so yeah sure comments.
- bearincar 2y ago[dead]
- eviks 2y ago> because there are no downsides to making a regular JSON parser accept comments. Ambiguity is just one of such downsides > We don't need a new format, we just need parsers for the existing format that are written by people who understand that Douglas Crockford is not their dad. That's a new format, you just don't want a name change
- codedokode 2y agoInstead of inventing "JSON with comments" format, why not simply use JSON5?
- iddan 2y agoIt's already invented and JSON w Comments is a lot simpler than JSON5 to parse
- dathinab 2y agoBut if you already decide to forgo the benefits of JSON (mainly the ecosystem/wide spread support) and use a niche solution why would you go for JSON5? That looks like a worst of both world solution IMHO. You are probably better of with a TOML -> JSON mapping and would be better of with YAML too if YAML hadn't had really stupid ambiguity pitfalls.
- williamdclt 2y agoYou don't lose all benefits. Ecosystem often isn't a problem (I don't need high interop, I need this JSON5 file for one specific purpose), and you certainly don't lose all benefits: - JS syntax compatibility (low cognitive overhead) - Decent balance between machine-readable and human-readable - High familiarity for developers (if they know JSON, which they likely do, they can work with JSON5 with near-0 learning curve) Plus, JSON5 support is _somewhat_ widespread (maybe ~50% of tools I use support json5 for config?)
- chippiewill 2y agoI agree, it's better to just use JSON5. Having a mess where JSON parsers sometimes do, and sometimes don't allow comments is a bad outcome. JSON5 is advantageous because it's explicitly separate - it has a different file extension, it needs different libraries. Also it supports a few other utility features people want (like trailing commas) without bringing in the whole dangerous kitchen sink like YAML does.
- billpg 2y agoIf you are going to put comments in your JSON, please use the /* */ style. It is often useful to express a JSON object as a single line of text. Comments that start from a symbol ("#" or "//") and continue to the end of the line can't be joined into a single line of text without throwing away the comments. /* */ is distinct by having an explicit end-of-comment symbol that allows meaningful text afterwards.
- bloak 2y agoAnd then you don't need to invent a new version of JSON: you just preprocess the file/string with the C preprocessor? (I don't like the C preprocessor but in some situations it's the easiest solution.)
- billpg 2y agoI would caution against using the C pre-processor, unless you're very careful indeed. {"data": #include "/home/myservice/secrets.json" }
- Pikamander2 2y agoSingle-line and multi-line comments have different use cases. Any good language should support both # and /**/ // is unnecessary, though. It adds nothing besides an extra character to type.
- est 2y agoOne the one hand, we see formats like protobuf elimilated field descriptors On the other hand, people are adding comments to formats like JSON.
- lifthrasiir 2y agoWhile the needs for comments in JSON are well understood, little discussions were made about which comment syntax and semantics should be used. It is not even clear that implementations should return comments as a part of data model! Almost all JSON alternatives, which number at least hundreds I believe, are either unclear or haven't given much thought about this. And those who do care about them are unpopular. sigh Given its importance, we should take this into the standard body. Namely, the IETF should be pressurized enough to update RFC 8259 for every nitty-gritty about comments. It is clear that this new version of JSON needs to address multiple use cases which are often mutually exclusive, so we probably need to introduce some short indicator for profiles at the very beginning of the document. (Yes, that means you should declare in advance that you want comments and other humane syntaxes. I don't think that's very hard when you do want comments.)
- xcombelle 2y agohttps://xkcd.com/927/ https://xkcd.com/927/
- euroderf 2y agoWould there be a way to tinker with JSON Schema to use it to specify comment syntax, and then wrap it up into a new RFC that leaves "legacy" JSON oblivious ?
- zxcvgm 2y agoI’m surprised HuJSON wasn’t mentioned in the list. Tailscale uses it for their config files. I did a hacky workaround by preprocessing my JSON config with regex, but found HuJSON later. https://github.com/tailscale/hujson https://github.com/tailscale/hujson
- sour-taste 2y agoWhat 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.
- szundi 2y agoAnd now starts 30 years of bugs, thank you.
- MathMonkeyMan 2y agoIt's true that Douglas Crockford is not my dad. My dad is a different person entirely. It's a bad idea to write JSON parsers that can accept comments. Comments are not part of JSON. There are plenty of extensions to JSON, and they have parsers. Use them. Or, use a language that is already an extension to JSON, like JavaScript or YAML.
- stoperaticless 2y agoI want to highlight, that extra bad part is keeping the name “json parser”. (Naming it my-custom-format parser would circumvent ambiguity)
- michaelmior 2y ago> It's a bad idea to write JSON parsers that can accept comments. Comments are not part of JSON. I would tend to agree, but I don't think it's such a problem if it requires an option to be enabled and the docs make it clear that incorporating comments means it's not really JSON anymore.
- dathinab 2y agoIMHO if you have human managed configuration do not use JSON, it's a pretty bad choice for it and adding comments is not (fully) fixing it or in other words IMHO if you have JSON you shouldn't have a need for comments, if you do there is something wrong
- paulmooreparks 2y agoI started writing a completely different language because I was annoyed with the limitations of JSON: https://github.com/paulmooreparks/Xfer https://github.com/paulmooreparks/Xfer Comparatively, writing an alternative JSON parser is probably a bit wiser.
- avodonosov 2y agoJust use EDN. Not only it supports comments and trailing commas, it allows to avoid commas at all (they are simply ignored by EDN). Commas indeed are just redundant and incur visual noise most of the time. [1, 2, 3] [1 2 3] ; much better The spec: https://github.com/edn-format/edn/blob/master/README.md https://github.com/edn-format/edn/blob/master/README.md Examples at github (261k files found at the moment) : https://github.com/search?q=path%3A*.edn+&type=code https://github.com/search?q=path%3A*.edn+&type=code Github search only shows the first 5 pages of results. To extract more results split the search with more specific path qalifiers: path:*a.edn path:*b.edn path:*c.edn
- avodonosov 2y agoAfter adopting EDN dont fall into the deceptive feeling that Douglas Crockford is you son.
- lukan 2y ago"Commas indeed are just redundant and incur visual noise most of the time." I would argue semicolons are and only sometimes commas. Personally I prefer [1, 2, 3] much more over [1 2 3]. With long numbers and dots and strings and whatever, the seperator is helpful for me.
- avodonosov 2y agoIf and when commas improve readability for you, feel free to use them in EDN.
- stoperaticless 2y agoThat possible when you control the creation process. Frequently you can’t control the creation (e.g.external system)
- anonymous344 2y agocan somebody please make online json inspector that can copy the selected value's path in different formats. this is huge pain and found 0 with this feature
- anentropic 2y agoHe's not my Dad, but I do follow him on Mastodon... where he had this to say on the topic a few days ago: https://layer8.space/@douglascrockford/113595316189101091 https://layer8.space/@douglascrockford/113595316189101091 > If the comment is important enough to be put in the text and remembered, then make it an explicit part of the data structure. That will also make it easier for tools to find it and process it in a useful way. {"comment": ...} > Use a preprocessor tool such as jsmin to remove the commentary before passing it to a JSON parser. I kind of wish JSON had trailing commas though
- michaelmior 2y agoJSON5 has both comments and trailing commas. Of course you can only rely on JSON5 if you're ever passing through anywhere expecting JSON. https://json5.org/ https://json5.org/
- remon 2y agoI'm not super invested in this debate one way or the other but arguing a comment should be part of your data rather than documenting what data is contained is a bizarre take on the question. Either be of the opinion it's a data format and comments are just out of scope (and using JSON for e.g. config is just a bad choice), or agree that allowing comments in JSON should be part of the spec since right or wrong it is used for config and other human edited use cases. JSON5's adoption seems to imply people are mostly on the latter side of the fence.
- anentropic 2y agoI don't find the argument incoherent at all either it's a data transfer format and comments should be stripped before transmission or the comments are part of the data model makes you have to think clearly whether the comments are just "notes to self" at authoring time, or something relevant to the consumer OTOH of course there are plenty of 'greyer' cases
- nlohmann 2y agoJSON for Modern C++ (nlohmann/json) is also accepting comments if you opt in, see https://json.nlohmann.me/features/comments/ https://json.nlohmann.me/features/comments/
- miningape 2y agoI've used this for some personal projects (not a C++ dev at work) - it has a really nice interface for interacting with JSON data. I just wish C++ had a better package system than copy pasting the headerfile from GitHub.
- nlohmann 2y agoIt's sure not perfect (currently overworking that section), but still: https://json.nlohmann.me/integration/package_managers/ https://json.nlohmann.me/integration/package_managers/
- red_admiral 2y agoIt's a case of someone designs a tool to do A, then a lot of people who have problem B see it and go, that's almost what I want, with just a few adaptations. JSON in its original form is fine if you want to pass data from a server to a browser's fetch request. No need for comments. (If you're passing data from one process to another, and neither of the processes is a browser, have you considered protobuf?) For humans writing config files, such as the VS Code one where you sometimes need to go in and do things by hand, both the ability to temporarily comment stuff out and do put comments above particular settings, are extremely useful if not essential. The "comment: '...'" approach doesn't work here or anywhere else where you have a schema to validate against. Comments are not part of how JSON was originally defined. It's technically correct (the best kind of correct, some say) that comments are not part of the spec. But comments are sure how most people who edit JSON as a human [want to] use it. If the spec says A but everyone is doing B because that's what best solves their problem, then either you write a new spec and call it JSON++ or JSON-C or something and watch most people switch to that, or you adapt the spec in the first place. We've seen this with markdown (ok, commonmark) and HTML already, among other things.
- michaelmior 2y agoIf you want JSON with comments (and a couple other extras), use JSON 5 instead. (It's effectively the JSON++/JSON-C you mention.) https://json5.org/ https://json5.org/
- shaftway 2y ago+1 for using protobufs. I'll go a step further and suggest using textprotos for configuration files. You get validation out of the box for free (making it hard to mis-type your keys), along with a strict contract for your configuration. Comments too. And no quotes on key names. I don't think trailing commas are supported in condensed repeated fields, but since there aren't commas between fields you can use the long format to avoid them. https://protobuf.dev/reference/protobuf/textformat-spec/ https://protobuf.dev/reference/protobuf/textformat-spec/
- eadmund 2y agoI appreciate Phil’s writing much of the time, but in this particular case I believe that he is very wrong. The whole point of JSON is that it is an object notation: JSON parses into a kind of lowest-common-denominator object, either a number, a string, an array, a hash table, a boolean or a null. Every language supports those, one way or another. You can read an object into your runtime, mutate it, then print it back out and only the mutated part will change (this is round-tripping). If comments were added, then to preserve round-trippability they would need to be readable. For that to work, they would need to live somewhere in the read-in object. But then, what would the result of reading this be? 3.14 # pi It can’t be 3.14; it has to be something like [3.14, #<COMMENT: "pi">]. What even is a comment object? Where would the comment go in an example like this? { "foo": "bar" # baz } Maybe the returned object is something like {"foo": #<COMMENTED-VALUE: "bar" " baz"}? But what is that type? It’s a huge can of worms! Sure, you could just give up on roundtripping. But it’s important! XML of course has support for comments, but they are objects within its infoset: when you read in an XML document, you can access the comments as part of it. One of the points of JSON is that one doesn’t need all the complexity of XML to get stuff done.
- nathell 2y ago> Sure, you could just give up on roundtripping. But it’s important! In the vast majority of cases, it’s not. If removing comments breaks roundtripping, then so does altering the indentation or adding/removing whitespace, even ever-so-slightly. EDN parsers strip comments when read – it’s not an issue in practice.
- deleted 2y ago[deleted]