Pseudo-JSON with unquoted property names

David-Sarah Hopwood david-sarah at jacaranda.org
Fri Jun 5 16:04:51 PDT 2009


Matthew Miller wrote:
> This observation may have been made before and I missed it, but allowing
> unquoted names can cause the following confusion:
> 
> var memberName = "foo";
> 
> var anObject = { memberName: "test" };
> 
> Now what should anObject.foo evaluate to?

undefined.

> Will it be obvious to most coders?

Yes. Anyway, unquoted names have always been allowed in JavaScript
with this semantics, and no-one is suggesting to *output* unquoted
names in JSON -- so if there were such confusion, the ES5 JSON encoder
would not be the source of it. The question is only whether to allow
unquoted names on input in JSON, in order to compensate for noncompliant
encoders.

(Note that this is somewhat different from Postel's "be liberal in
what you accept" rule, because it is specifying *precisely* what must
be accepted, and requiring everything else to be explicitly rejected.
I do not accept the validity or wisdom of Postel's liberality rule
when it is applied to unspecified inputs.)

> This confusion will not occur if you do not allow unquoted names.
> (IE6, IE8, FF3 all report it as undefined, btw)
> 
> 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. 

Thanks for this data point. The fact that you would have to change
the server code is significant; if you didn't have control of the
service, that would be more difficult.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the es5-discuss mailing list