Pseudo-JSON with unquoted property names

John Cowan cowan at ccil.org
Fri Jun 5 13:57:58 PDT 2009


Matthew Miller scripsit:

> var memberName = "foo";
> 
> var anObject = { memberName: "test" };
> 
> Now what should anObject.foo evaluate to? Will it be obvious to most
> coders? This confusion will not occur if you do not allow unquoted
> names. (IE6, IE8, FF3 all report it as undefined, btw)

So they should:  { "memberName": "test" } and { memberName: "test" } mean
exactly the same thing.  However, { "class": "sophomore" } is valid ES3,
whereas { class: "sophomore" } is not.  Hence the JSON rule is "Quote
all names".

> The app I work on for my employer has a lot of JSON with unquoted
> names that gets sent from the server for AJAX calls. I don't think
> there would be any uprising over having to go back and quote the
> names. That is not a major undertaking for our app at least.

That's good.

-- 
A few times, I did some exuberant stomping about,       John Cowan
like a hippo auditioning for Riverdance, though         cowan at ccil.org
I stopped when I thought I heard something at           http://ccil.org/~cowan
the far side of the room falling over in rhythm
with my feet.  --Joseph Zitt


More information about the es5-discuss mailing list