by CWIZO · 1y ago · 0 comments
It helps to learn your history before you criticise something and claim it is useless.
JSON is the way it is mainly because it is just JavaScript and that meant that every browser in the world already supported it before JSON was even invented. It is THE reason why it is as popular as it is.
var myObject = eval(httpResponseBody)
Of course, this is vulnerable to all kinds of issues so we got JSON parser, and later JSON became part of the Web API.(Sadly, Crockford's post about this reasoning was on Google Plus and is no longer online.)
{copyright comment : "JSON doesn't require/enforce specific comments is a good thing" }
{comments : "JSON parser is not an 'comment' editor! }
Don't know whtat the google plus article covered, but Crockfor's comments : https://www.linkedin.com/posts/douglas-crockford-724600109_j...
One that keeps killing me is:
return
(complicated-multi-line-computation)
Since it can put a semicolon at the end of the first line, it does. Which means the return value is undefined, and the rest of it is just some code that it never actually reaches. A linter will fix that, but I find the usual fix a bit ugly: return (
(complicated multi line computation)
) const foo = someFn()
(foo as Bar).doSomething()There is nothing in the JSON spec that prohibits pre/post non-json parsing search / replace 'end of line' marker with one or more commas.
JSON spec just tells one what the JSON parser expects, not what the end user needs/wants. (GPT-JSON not withstanding)
> ... before you criticise something and claim it is useless.
These 2 statements feel quite far apart.
The easy solution would be to go the JavaScript route and make commas optional, like JavaScript does with semicolons. You could even introduce vague and easily forgotten rules about commas being inserted between oneliner dictionaries.
I think the question "why" is easily answered, but "why should it still" is more difficult.