
ECMAScript 5 Strict Mode, JSON, and More - mcav
http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
======
axod
One irritation I have with native JSON parsing, is that it seems to require
quotes around keys. I don't understand why, and think it's a bad choice.

For example, in js code, eval, other JSON parsers etc, the following works
fine as you'd expect:

{foo:"bar"}

However, using the JSON.parse function, it'll fail. The following works:

{"foo":"bar"}

If anyone can shed some light on this, I'd be interested. I'd rather not send
tons of useless quotes if I don't have to.

~~~
Sephr
Nobody seems to notice this, but using quotes stops you from error of using
{foo:"bar"}. In JavaScript, {foo:"bar"} is not an Object, it is a code block
containing a labeled code block with the label, foo, in it with a string,
"bar". This is what {foo:"bar"} really means in JavaScript:

    
    
        {
          foo: {
            "bar";
          };
        }
    

Labels cannot be strings, so quoting them will help you catch this error
earlier.

~~~
tlrobinson
I'm not sure if your particular example is correct, but you're right that
there are certain ambiguous cases involving labels and object literals.

There was a really good talk recently that touched on this, but I can't
remember who gave it or what it was called.

