Live data from Hacker News

JSON with Commas and Comments

nigeltao.github.io

61–70 of 251 posts

Re: JSON with Commas and Comments

#61

> Yes, Doug Crockford deliberately removed comments from JSON but people keep putting them back in. If we’re going to have comment-enriched JSON (e.g. for human-editable configuration files), we might as well have a standard one. The text "deliberately removed comments from JSON" links to https://web.archive.org/web/20150105080225if_/https://plus.g... where Doug not only explains the reason, but also a solution which…

If I’m going to use “JSON with comments” that I have to run through a preprocessor before parsing, why not just use a language where comments are explicitly allowed (YAML, TOML, etc.)? Crockford’s answer is not a solution. His words can be rewritten as: “you want comments? Use a different language that looks and feels like JSON, but isn’t.” All that does is add confusion. The only reason JSON is as popular as it is i…

> The only reason JSON is as popular

I mean I remember using XML for serialization back in the day and how it made we want to kill anyone who was involved in its creation. JSON won because it’s a great and simple standard and yes because it maps 1:1 to js. It was very popular with people who hated js when it came out too - just because of how much better it was than the other options

Re: JSON with Commas and Comments

#63
I recently did a thing in YAML because I needed to deserialize the files at runtime and one of the fields is a multi-line Kusto query. if I ever need to hand generate a files with multi-line text in it again, I won't use json.

Re: JSON with Commas and Comments

#64

Aren't these deserialization options already in, say, Jackson?

These options are already in lots of parsers. That's part of why this proposal is attractive: we don't need much to start using it.

In fact I've been using JSON with comments and trailing commas in my own projects a lot already, and I imagine lots of other people have converged to the same idea since these are really the only two pain points when handwriting JSON. It's about time we give it a formal name.

Re: JSON with Commas and Comments

#65

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…

JSON parsing is already a minefield. Please see [0], specifically this chart [1]. As mentioned in a sibling comment, I think a new mimetype makes a lot more sense sense than stirring this pot further.

[0] http://seriot.ch/parsing_json.php

[1] http://seriot.ch/json/pruned_results.png

Re: JSON with Commas and Comments

#68

Earlier quoted context omitted.

Current parsers cannot start returning BigInts instead of numbers without that being a breaking change. And I'm not sure anyone wants a format where the result may change types based on the size of the number, especially for languages where arbitrary precision types are not compatible with other numbers.

> Current parsers cannot start returning BigInts instead of numbers without that being a breaking change. Current parsers aren't uniform here. Since the JSON spec is silent on what post-parsing format is used for numbers, each parser is free to do whatever makes sense in the context of the host language. I reckon you'll find some JSON parsers use bigints already, especially in languages with first-class bigint suppor…

> I reckon you'll find some JSON parsers already use bigints already

Yep. Python is one such language. I've seen this catch people by surprise when they discover their serial number (which granted, should have been a string in the first place) doesn't survive a trip from Python to JSON to Javascript, among other languages.

Re: JSON with Commas and Comments

#69
I actually think the lack of comment support in JSON has resulted in better naming and better documentation by those who create JSON to be consumed by others. I don’t want comment support in JSON at this point personally.

Re: JSON with Commas and Comments

#70
post #43

Earlier quoted context omitted.

I can't believe that anyone who has ever wanted to comment a package.json file could think Crockford's argument is anything but nonsense. The problem is these files are both edited by humans, and by a plethora of tools. Without a standard comment format, it's been a nightmare trying to comment package.json file in a way that doesn't break something in the NPM/Node ecosystem.

Using JSON for configuration could be the mistake? That wasn't the original goal of JSON.

Exactly, hasn’t NPM caused enough problems? Now you want to spread that mindset to JSON?
Post reply on HN