W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2006

[whatwg] JSON encoding

From: Dean Edwards <dean@edwards.name>
Date: Fri, 03 Nov 2006 18:05:46 +0000
Message-ID: <454B84FA.9040304@edwards.name>
Douglas Crockford wrote:
>  > I think the hazard is very real and very serious.
>  > I don't see any additional expressiveness enabled by toJSONString.
> 
> No one is more concerned about the security of the platform than I am.
> There isn't a security issue here. The hazard, if there is one, is
> certainly not serious.
> 
> This is a convenience issue. Having toJSONString as a builtin is a 
> convenience, removing the need to load json.js.
> 

Why not override the toString method?

Object.prototype.toString(type) {
   if (type == "json") {
     // return a json serialisation
   } else {
     // return the usual string conversion
   }
};

That way legacy browsers can also support JSON serialisation without 
breaking "for in" enumeration.

-dean
Received on Friday, 3 November 2006 10:05:46 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:49 UTC