Property Iteration in JSON serialization

Brian Kardell bkardell at gmail.com
Tue Oct 13 23:37:07 PDT 2009


On Tue, Oct 13, 2009 at 10:54 PM, Luke Smith <lsmith at lucassmith.name> wrote:
>
> On Oct 13, 2009, at 9:24 PM, Brian Kardell wrote:
>
>>
>> There are potentially some additional practical upshots beyond human
>> readability to this which I won't get into here until I find out:  Is
>> it even plausible to accomplish this with new built in JSON supports?
>>
>> To be specific, if it's not clear... Given an instance of an order
>> object, I would like to serialize it like this:
>>
>> {
>>   "items": [
>>       {
>>           "description": "A bottle of rum",
>>           "itemId":  13523,
>>           "price": 12.94,
>>           "quantity": 6
>>       },
>>       {
>>           "description": "A bottle of whiskey",
>>           "itemId":  23423,
>>           "price": 6.95,
>>           "quantity": 24
>>       }
>>   ],
>>   "orderNumber": 1234123,
>>   "shipTo": {
>>       "city": "Seattle",
>>       "name": "Jane Doe",
>>       "state": "Washington",
>>       "streetAddress": "123 Main Street",
>>       "zip": 12345
>>   }
>> }
>
> It is possible to sort object keys in a replacer function.  See
> http://gist.github.com/209826
>
> Currently FF3.5.4 doesn't properly apply replacer functions, but Safari 4,
> WebKit, IE8, and Chrome 3 work fine for this task.
>
> Luke
>

But I guess your example gets to the gist (ironically, given the url)
of the question: It seems to be implying that there is a specific
(insertion) order maintained by the instance itself and reflected in
iteration... The difference being something more like a TreeMap than a
HashMap - but is that part of the specification?  I thought that it
specifically wasn't.


More information about the es-discuss mailing list