Live data from Hacker News

JSON with Commas and Comments

nigeltao.github.io

91–100 of 251 posts

Re: JSON with Commas and Comments

#91

Alternatively, just use JSON as a low-level data interchange much like a CSV file. Put all your human-managed content in a configuration language that emits JSON, like jsonnet, cue, dahl, etc. These languages add comments, function, variables, and much, much more (like fancy data cascades, validation, schemas, imports, etc.) to make managing configuration at scale easy.

Why even go to the trouble of converting it to json then?

Re: JSON with Commas and Comments

#92

Rather than keep making new variants of JSON, it'd be nice if somebody could convince some mainstream language maintainers to just update their built-in JSON parser to add optional features like skipping over comments and not caring about trailing commas. Most parsers support various flags already to configure things, so there could just be an ALLOW_COMMENTS flag and ALLOW_TRAILING_COMMAS flag. As a case in point, th…

ruby's JSON.parse accepts comments (but not trailing commas)

Re: JSON with Commas and Comments

#93

Earlier quoted context omitted.

I’ve personally never encountered any combination of JSON-encoded data and JSON parser that didn’t work perfectly together. I don’t know whether the right trade-offs were made between interoperability and other features, but I’d say it’s very clear that if interoperability was a chief design goal, it was executed extremely well.

I don't understand why you keep making the same circular arguments. If the lowest-level standard for JSON-encoded data also included comments and trailing commas, than I have no doubt that every combination of JSON-encoded data and JSON parser would be able to parse that. Instead, it wasn't put in the lowest level spec, so instead what you have are lots of individual parsers with non-compatible custom flags. If Crock…

> If Crockford's argument was "I got rid of comments because people were using them for preprocessor directives", then he just made the problem a million times worse because now there are a million different, incompatible "preprocessor directives"

No, because his goal was to make JSON a highly-compatible interchange format, which it is! There are roughly zero incompatible preprocessor directives, and roughly zero problems using JSON to exchange data between parties. Seriously, when have you received JSON that you couldn’t immediately parse with your standard JSON parser of preference? The fact that some people might devise their own tools to store incompatible JSON on their end with things like comments, and strip those things out when transmitting them in order to make them compatible JSON, does not qualify as an incompatible preprocessor directive. On the contrary, thats precisely the intent of the choice to not have comments in JSON.

Re: JSON with Commas and Comments

#95
post #66

Why can't these no-brainer features just be added to browsers without a new standard!!

That would make fetching JSON data significantly more complicated. You'd need to write your fetch call to detect if the browser supports comments and commas in JSON, and then make the request to the server to ask for whichever variant the user's browser supports, presumably with a different Accept header. Users who haven't updated to a new version of the browser would still ask for the old JSON format, and users who have updated would ask for the newer version.

That would mean your API would need to serve different variants based on the Accept header, and your backend code would need to generate the two different variants.

And then you'd have to question if sending API responses with unused things like comments is actually a good idea given it's entirely wasted data in a production environment.

I suspect few people would use a newer JSON format until it's been available for a long time, and even then they wouldn't use it on big sites.

Re: JSON with Commas and Comments

#96
post #74

Earlier quoted context omitted.

ISO-8601 not good enough for you? It’s a standard, human readable, has every datetime detail, every language that supports JSON can read it. What’s missing?

Be careful ever saying “every datetime detail”! An obvious one is that ISO 8601 can’t represent the location of the local time with enough information to know the current (or historical) daylight saving time rules for that location. You might not need that now, but you might if you’re building a calendar app! ISO 8601 can represent a simple offset from UTC, but it can’t do a lot of the things that the IANA time zone…

Fair, very fair. Have gotten bit by that in the past.

Adding an IANA library to the ISO8601 library (often part of the same lib) has so far solved that problem for me. I’m sure it starts struggling with dates before the early 1800’s though.

Also doesn’t work well if you’re dealing with relativistic effects I think.

Re: JSON with Commas and Comments

#97

Earlier quoted context omitted.

I’ve personally never encountered any combination of JSON-encoded data and JSON parser that didn’t work perfectly together. I don’t know whether the right trade-offs were made between interoperability and other features, but I’d say it’s very clear that if interoperability was a chief design goal, it was executed extremely well.

> I’ve personally never encountered any combination of JSON-encoded data and JSON parser that didn’t work perfectly together. As recently as 2017, the Google Translate API used to return completely invalid JSON with empty array indices instead of nulls ([,,,] instead of [null,null,null,null]). This broke several JSON parsers until they patched around Google's cavalier abuse of the language. Your experience of everyth…

That sounds more like a bug that, because the group responsible for the bug didn’t fix the bug and was extremely important to the community, developers of JSON parsers had to put in bug fixes on their end instead. I’m not familiar with the details of that event, but it doesn’t sound like anyone was actually accepting this as a new valid variant JSON, and AFAIK it didn’t lead to the propagation of different variants of JSON that are both in significant use but are incompatible. Or to put it another way, I don’t think people need to worry about whether they’re using “Google Translate JSON” or “Standard JSON.”

Re: JSON with Commas and Comments

#98
post #94

Just use YAML. JSON is valid YAML.

Problem is... YAML sucks, as human readable format

No it doesn’t. I know the HN-crowd feeling about this, but no, YML doesn’t suck as a human configuration language. TOML or XML properly suck. YML is actually a superset of JSON with comments and less brackets if you want. It’s widespread and supported and fulfill the need of OP, so no need to add yet another format. Or use JSON5. But please not yet another standard

Re: JSON with Commas and Comments

#99
Well at least the article is aware of its own vanity. I was going to cite the XKCD about “standards” but it did for me. Just use JSON5 and stop losing time (or YML, yes it’s not that terrible for configuration files)

Re: JSON with Commas and Comments

#100

Rather than keep making new variants of JSON, it'd be nice if somebody could convince some mainstream language maintainers to just update their built-in JSON parser to add optional features like skipping over comments and not caring about trailing commas. Most parsers support various flags already to configure things, so there could just be an ALLOW_COMMENTS flag and ALLOW_TRAILING_COMMAS flag. As a case in point, th…

> Rather than keep making new variants of JSON, it'd be nice if somebody could convince some mainstream language maintainers to just update their built-in JSON parser to add optional features like skipping over comments and not caring about trailing commas.

I think the most correct way to deal with this problem is to get IETF and ECMA to update the JSON standard first. Honestly, comma-after-final-element and comments are such important quality-of-life features that I never understood why they weren't part of the original spec.

On the other hand, it might be easier to just adopt TOML and forget about JSON.

Post reply on HN