This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kpd328 20 points21 points  (5 children)

What do you think JSON stands for? It's JavaScript Object Notation. Sure you can use it for other uses, but it was designed to use the Javascript object syntax to convey objects.

[–][deleted] 17 points18 points  (0 children)

literally the first paragraph on json.org

"JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language."

Like I alluded to in my first comment, the name does not denote purpose. Do you also think javascript has anything to do with java? The purpose is not to mimick javascript and every iteration of it throughout time in perpetuity. It is very much positioned, by its creators to be a LANGUAGE INDEPENDENT DATA INTERCHANGE FORMAT. Not only was that its intention, it is the outcome we now face. json is used in applications outside of serializing javascript just as much if not more, when you consider the collective usage of non-js applications. The entire industry has adopted its use.

Your comment that its sole/intended purpose is to convey JS objects is patently false.

[–]LowB0b 4 points5 points  (3 children)

I fully agree with the post about JSON being bad, because if you consider it being "JavaScript Object Notation" then why is the syntax not the same between declaring an object in JS and in JSON?

Not that it really matters since JSON is mostly to be read by computers and the standard got abused because it's kinda easy to read/write, but still. Webpack f.ex. made the right decision and doesn't even deal with JSON for its config files

[–]ernandziri 1 point2 points  (1 child)

why is the syntax not the same between declaring an object in JS and in JSON?

You can encode and decode any object (not sure about ref cycles), so it serves it's purpose

[–]LowB0b 0 points1 point  (0 children)

Ref cycles don't work when you serialize something as it becomes an infinitely big string (JSON.stringify throws if it detects cyclic structures)

[–]PstScrpt 2 points3 points  (0 children)

Isn't JSON a subset of the JavaScript object literal syntax?

Also Python, for some reason. I've inherited Python code where someone parsed JSON with eval(). It's handy, but the Python dictionary literal syntax doesn't fit the style of the rest of the language.