Might still be maintained but http://json.org/json2.js has been
recommended for quite a while. json.js was severely broken, indeed.

On Wed, Nov 19, 2008 at 10:20 PM, Tobie Langel <[EMAIL PROTECTED]> wrote:
>
> Very old as in may 2008 ? http://json.org/json.js
>
> ;)
>
> On Nov 19, 10:10 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote:
>> OK, I turned to reading the docs :)http://www.prototypejs.org/learn/json
>> Although, they refer to a very old version of Crockford's json lib
>> which no longer extends Object.prototype the conclusion probably holds
>> true.
>>
>> Anyway, is there a way to have json2.js and prototype play nice with each 
>> other?
>>
>> On Wed, Nov 19, 2008 at 9:40 PM, Malte Ubl <[EMAIL PROTECTED]> wrote:
>> > Hey,
>>
>> > is Prototype designed to use a built in JSON stringification mechanism?
>>
>> > The most popular library, json2.js (http://json.org/json2.js), states
>> > pretty clearly that the toJSON method is not supposed to return a
>> > serialized result (which it would turn into a string) but should
>> > rather return something that can be automatically stringified by the
>> > library itself. That might be any kind of value, but besides that it
>> > can be also be instances of Object. Joose.Storage thus returns an
>> > Object that represents the state of the Joose object and which
>> > includes extra info that can be used for reinstantiation. The nice
>> > side effect of this is, that complex structures of nested objects are
>> > no problem because the stringifier will once again call toJSON on the
>> > children (if toJSON would return a string it would have to implement
>> > this itself).
>>
>> > If Prototype does indeed need a more complex toJSON method, we could,
>> > of course, detect that and change our behavior.
>>
>> > Bye
>> > Malte
>> > --
>> >http://code.google.com/p/joose-js/
>> >http://blok.appspot.com/
>>
>> > On Wed, Nov 19, 2008 at 3:51 PM, kangax <[EMAIL PROTECTED]> wrote:
>>
>> >> On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote:
>> >> [...]
>> >>> The source code of the test is located 
>> >>> athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag...
>> >>> Interestingly the statement at line 49 succeeds. (It stringifies a
>> >>> Joose object to JSON and and deserializes it again)
>> >>> The statement on line 81, howevery, fails to produce correct JSON. The
>> >>> produced string looks like this:
>> >>> {"test":"[[object Object]]","another":{"a":1}
>>
>> >>> When you set a firebug break point in Storage.js line 11 you can see
>> >>> that the code goes deeply into Prototype.js territory.
>>
>> >> The "joose" object (the one that's being tested against) seems to have
>> >> `toJSON` method:
>>
>> >> function () {
>> >>  return this.pack(Joose.Storage.TEMP_SEEN);
>> >> }
>>
>> >> That method seems to return an object, rather than a string
>> >> representation of an object. Prototype's `Object.toJSON` just happens
>> >> to delegate its logic to passed object's `toJSON` (effectively letting
>> >> "joose" object decide "what to do"). "joose" object returned from
>> >> `toJSON` is then turned into "[[object Object]]" via
>> >> `Array.prototype.join` invoked on an array it's contained within (join
>> >> performs `toString` on each of array's items, if I'm not mistaken).
>>
>> >>> Bye
>> >>> Malte
>>
>> >> [...]
>>
>> >> --
>> >> kangax
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to