Thursday, 27 January 2005

JSON and its implementation gotcha

Stephen points to a slashdot post about JSON (Javascript Object Notation) promoted by Douglas Crockford.

Fablusi replies heavily on JSON for its communication with the server and inter-module communication. However during our implementation, I discover a few issues which are not discussed anywhere else known to me. (Please point me to any discussion of JSON, if you know of any).

1. Internet Explorer generally fails to initialise an object in JSON notation. However, it loads an array of objects correctly. So if you want to initialise a JSON object in cross browser application, use this pattern:
thisObj=eval("[{'membersName':'MemberValue',...}]")[0];
i.e. transfer using an array instead of an object, or add the square brackets at the client side before conversion.

2. There are other even lighter weight mechanism for transferring a set of data of the same object. (by not repeating the membersName many times..., but require some software support at the receiving end.)

3. the evaluated object does not have any methods. It is data only. This can proved to be quite difficult to use the object effectively.

4. Eval is a depreciated Javascript method. :-(

Current Fablusi v2 users will notice that the save format of the simulation data is in traditional Javascript object initialisation format - NOT JSON because I need the initialised objects to have methods defined in the system.

While JSON is a good idea and I look forward to seeing how JSON-RPC may work, use with an understanding of its limitation. The benefit (light weight) outweighs its limitation.

No comments: