Live data from Hacker News

JSON with Commas and Comments

nigeltao.github.io

21–30 of 251 posts

Re: JSON with Commas and Comments

#21

IMO it would also be really nice to have non-string keys in objects, like: { [1, 2]: "a", [3, 4]: "b" }

You realize this would push outside of what JavaScript provides?

    'Welcome to Node.js v15.7.0.
    Type ".help" for more information.
    > { [1, 2]: "a" }
    ({ [1, 2]: "a" })
        ^
    Uncaught SyntaxError: Unexpected token ','
Thar' be dragons! https://stackoverflow.com/questions/32660188/using-array-obj...

Re: JSON with Commas and Comments

#22

IMO it would also be really nice to have non-string keys in objects, like: { [1, 2]: "a", [3, 4]: "b" }

it's usually a pretty bad idea to have a mutable object (the array) as a key. Though I guess if you consider it as a 'tuple' since when in json form it can't be modified I guess it'd be technically possible, though with some heavy caveats.

There’s no concept of mutability in JSON. A JSON parser could give you immutable arrays and maps if it wanted to.

Re: JSON with Commas and Comments

#23

> 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…

Crockford regularly displays a stunning degree of tunnel vision. Without a standard format for comments, you have no reason whatsoever to expect the ad-hoc comments in a JSON file made by anyone who isn't you to be styled like JavaScript comments. And if your response is "then everyone needs to use JavaScript-style comments", well, TA-DA, you've just added comments to the spec. You can't have it both ways. > It's imp…

I wish JSON supported comments, but I don’t really understand your criticism. You say:

> Without a standard format for comments, you have no reason whatsoever to expect the ad-hoc comments in a JSON file made by anyone who isn't you to be styled like JavaScript comments.

But, since comments are not supported in JSON, you can expect JSON from external sources to contain no comments whatsoever.

That’s precisely Crockford’s point: he didn’t want the format to have a comment syntax that works across different parties so that the only way to use comments is internally, i.e. with a custom comment syntax that you strip before interacting with external sources.

Re: JSON with Commas and Comments

#26

> 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…

the very simple thing lacking in this solution is that sometimes you want to programmatically _add_ comments to (or preserve comments within) some output file format. If they must be stripped before parsing, then it is definitionally impossible to do either of these things.

It's not unlike saying "actual code shouldn't allow comments - you can have a separate preprocessor in your non-code file that strips those out." Sure, you could do that, but all your line numbers would be meaningless and everyone would hate the language from day 1.

Re: JSON with Commas and Comments

#27
post #21

IMO it would also be really nice to have non-string keys in objects, like: { [1, 2]: "a", [3, 4]: "b" }

You realize this would push outside of what JavaScript provides? 'Welcome to Node.js v15.7.0. Type ".help" for more information. > { [1, 2]: "a" } ({ [1, 2]: "a" }) ^ Uncaught SyntaxError: Unexpected token ',' Thar' be dragons! https://stackoverflow.com/questions/32660188/using-array-obj...

it's true JS doesn't support this, and it's also true that any JSON that supported it would therefore no longer be _JavaScript_ object notation.

However, it's equally true that a better language and object notation would support non-string scalar keys.

Re: JSON with Commas and Comments

#29

> 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…

Given the number of times people have invented and re-invented JSON + comments, I think it's clear there is a demand for JSON + comments, and that Crockford's view that you can solve everything by asking people to manually strip the comments out before parsing the JSON isn't viable.

Re: JSON with Commas and Comments

#30
post #28
post #24

Earlier quoted context omitted.

Would you like to spell out what TFA means?

https://en.wiktionary.org/wiki/RTFA

I'm aware, thanks.

I wanted to see if CameronNemo would spell it out.

I'd like to point out the HN Guidelines:

https://news.ycombinator.com/newsguidelines.html

> Please don't comment on whether someone read an article. "Did you even read the article? It mentions that" can be shortened to "The article mentions that."

Even putting aside what "F" stands for, this means that comments like TFA or RTFA are not in the spirit of the discussion here.

Post reply on HN