> If I were in an environment where the JSON object and its methods were
> not available, would doing something like this:
>
> if (typeof JSON === "undefined") {
>     JSON = {
>         stringify : function (o) { return Object.toJSON(o); },
>         parse : function (s) { return String(s).evalJSON(); }
>     };
>
> }
>
> produce the same output as using native JSON or the json2.js library,
> or would there be differences? If there would be differences, what
> would they be?

There would be a difference.

JSON and json2.js both rely on an implementation based on the idea
that toJSON must return "the value to be stringified".

json.js - on which our implementation is based - relied on the idea
that toJSONString (and we're using toJSON in our implementation) must
return a stringified value.

What this typically means is that for json2 'foo'.toJSON() will return
'foo', so JSON.stringify will add the quotes. Our version of toJSON
actually returns '\"foo\"' so passing it to JSON.stringify means it
will be escaped and quoted twice.

We'll fix this for 1.7.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to