Hacker News new | ask | show | jobs
by throwaway81523 1704 days ago
> That said I think adding a trailing comma and comments to json wouldn't be a big stretch.

Sadly, json's designers suffered from the same hubris as the designers of markdown and gemini, when they decided to not include a version number in the file format. So you are kind of hosed if you want to make a change like that.

Before json there was xml (ugh), but before xml there were Lisp S-expressions, which seem to have handled all these issues perfectly well 50 years ago. Yet we keep re-inventing them. Greenspun's tenth law is still with us.

1 comments

It's just a matter of parser implementation. These changes are backwards compatible. If python decided to add support for comments and trailing commas in json.loads, that would become the new standard, at least for data scientists, not for web devs. All the other ones would then follow.
Now whatever generates your data has to know what parser is going to read the data. The parser can't tell right away whether the data has those trailing commas. They are optional, so they might not start appearing until after gigabytes of output have gone by. So you can't count on a quick error message in the event of a version mismatch.
If you have gigabytes of handwritten JSON (if it's not handwritten, trailing vs non-trailing commas surely don't matter), then I feel like you're doing something wrong.

Though I'm sure someone's going to step in and say "Have you not heard of [stupendously niche use case]? Are you living under a rock!?" etc etc ;)

It's silly to not write your software to handle every possible input instead of every input you think is likely based on some predictions about humans. Failure to do that is why YAML is so broken.

JSON isn't a format conducive to handwriting even if it probably should have made more accomodations for that at the start. Right now it can't even handle trailing newlines. But if you want to fix that, call it something different (maybe even JSON2), for heaven's sake.

I doubt anyone would handwrite an entire gigabyte JSON document, but they might hand-edit a machine-generated one to make a change someplace in it, end up putting in a trailing comma, and have the document pass their local tests but crash a remote parser.

> Though I'm sure someone's going to step in and say "Have you not heard of [stupendously niche use case]?"

> they might hand-edit a machine-generated one to make a change someplace in it

Ah, there's [stupendously niche use case] ;)

Seriously, though, I do agree with your point that good software should handle every edge case. I'm not arguing that.

But the case for having trailing commas does seem to be generally predicated on handwritten JSON, so I'm saying it's _unlikely_ it would be used in that way, and therefore that such failures would be rare and thus not a very grave counterargument.

You also have to think about security implications of a hostile client being able to crash a remote parser with gigabytes of context, though if it crashes on malformed json then they could do that with a much shorter fragment. In the well intentioned case, being paged in the middle of the night to debug a weird crash isn't fun, so it's better to have an accurate diagnosis (version mismatch) in the log if not prevent the crash outright. There is also the matter of every weird javascript implementation that would have to be updated, if JS can't already accept the trailing commas. It just doesn't seem worth hassling over.