JSON decoding

Erik Arvidsson erik.arvidsson at gmail.com
Fri Oct 20 12:59:15 PDT 2006


[Replying all this time]

Yes. This is a problem because you cannot tell if the data contained a
String or a Date.

({string: "20061020125156", date: new Date}).toJSONString() ->
{"string":"20061020125156","date":"20061020125156"}

...like Bob said...

On 10/20/06, Brendan Eich <brendan at mozilla.org> wrote:
> On Oct 20, 2006, at 3:36 PM, Erik Arvidsson wrote:
>
> > If Date is serialized as an ISO strings the process of encoding and
> > decoding loses information. If Dates are added to JSON then they
> > should be encoded using new Date(ms). However Dates are not supported
> > in JSON today and removing them from JS2 seems OK.
>
> ES4 also standardizes Date.parse to accept the same ISO 8601 date
> strings, so I don't believe any information is lost.
>
> You're right that this automatic encoding of Date objects as ISO
> strings does not result, when decoding, in Date objects again.
> Fixing that would require a pass over the decoded structure, or a use
> of the optional object hook on the enclosing object.  Is this a problem?
>
> /be
>


-- 
erik



More information about the Es4-discuss mailing list