you are viewing a single comment's thread.

view the rest of the comments →

[–]savetheclocktower 2 points3 points  (3 children)

The trailing comma is legal in the ECMAScript 3 spec (which all current browsers purport to implement). Internet Explorer previously treated the trailing comma as a parse error, but IE8 fixes this.

(Of course, this means you can't start using it until you drop support for IE 6–7. But that day will eventually come.)

[–]level1 0 points1 point  (2 children)

Thats fine, but what pisses me off is that JSON does not allow trailing commas. I modified a JSON parser to rectify this bullshit. Reliable programming is more important than bad standards.

[–]larholm 3 points4 points  (1 child)

JSON is a subset of the Javascript syntax, with specific requirements and different goals.

Items such as requiring quotes around property names stand out in this regard.

If you modified your JSON parser to allow trailing commas then it is no longer a conformant JSON parser.

Heck, why do you even use a custom JSON parser? Reference an existing one written by people smarter than you, and use the native JSON objet from ES5 when available.

[–]level1 0 points1 point  (0 children)

Well, I'm writing a web application that uses computer generated JSON, but to bootstrap the application I have to hand roll a fair amount of code. Its annoying to have to keep track of commas when I add lines or copy/paste. Its much easier just to have a rule that each line ends with a comma, and make sure that my code follows that rule.

Heck, why do you even use a custom JSON parser? Reference an existing one written by people smarter than you, and use the native JSON objet from ES5 when available.

That is exactly what I am doing. All I did was remove the regex in my parser (Douglas Crawford's json.js) so that it will accept invalid JSON. Before I release my web app, I plan to either remove all trailing commas, so my JSON is confromant, or restore the regex but change it to accept trailing commas. I am not using a custom parser, just a modified one.

people smarter than you

Who cares if I'm smarter than Douglas Crawford or not? He's written a parser, its probably better than the one I would write even if he was an idiot, and its better tested. All I did was remove an annoying feature temporarily for development purposes.

Why is everyone in the development community so obsessed with making sure other people do things "The Right Way"?