Property Iteration in JSON serialization

Patrick Mueller pmuellr at yahoo.com
Wed Oct 14 05:41:50 PDT 2009


On Oct 14, 2009, at 2:42 AM, Oliver Hunt wrote:

> All ES implementations are required to enumerate object properties  
> in the order of insertion, regardless of internal representation,  
> and the JSON object definition defines the replacer execution in  
> terms of that standard object enumeration.

I understand that's what all (or most) of the implementations actually  
do, but the ES5 spec I'm looking at - Ecma/TC39/2009/043 - doesn't  
actually say it's required.

In 12.6.4 discussing the for-in statement, it says: "The mechanics and  
order of enumerating the properties (step 6.a in the first algorithm,  
step 7.a in the second) is not specified."

In 15.2.3.14 discussion Object.keys(), it says: "If an implementation  
defines a specific order of enumeration for the for-in statement, that  
same enumeration order must be used in step 5 of this algorithm."

In 15.12.2 discussing JSON.parse(), it says: "The ordering of the  
Strings should be the same as that used by the Object.keys standard  
built-in function."

In 15.12.3 discussing JSON.stringify(), it says: "The ordering of the  
Strings should be the same as that used by the Object.keys standard  
built-in function."

Sorry, property ordering is an unfortunate pet peeve of mine.  :-)

Patrick Mueller - http://muellerware.org/






More information about the es-discuss mailing list