JSON Encoding

Douglas Crockford douglas at crockford.com
Fri Oct 20 13:25:37 PDT 2006


The current proposal provides a default decoding of dates as ISO strings. If you 
do not like that default, you can write your own toJSONString function and 
attach it either to your date object or to Date.prototype. This allows you to do 
anything you like. You can even generate non-JSON forms, although that is not 
recommended.

One possible encoding is to emit your own date object along the lines of

     {
         "type": "Date",
         "Date": ...what you like...
     }

You can then use the hook feature of parseJSON to turn such objects into dates.

The filter function is intended to help honor protocol contracts, assuring that 
JavaScript's dynamic object behavior does not lead to accidental sending of 
unintended members to the server.



More information about the Es4-discuss mailing list