JSON and Cocoon

Posted on Thu 17 November 2005

I'm currently pondering over the (radical) changes that Cocoon needs to stay mainstream in the changing world of web applications frameworks. Among other things, I just had a light bulb moment about JSON.

JSON makes it very easy to send data to an Ajax client. As it's plain JavaScript, just eval() it and you have an object to work with.

Now how does this fit with Cocoon, which is primarily based on XML processing pipelines? Simple: let's write a JSONSerializer, that would basically replace square brackets with curly braces!

But wait, there's more to that: what if the data isn't the result of a pipeline, but just a simple object you already have at hand in your flowscript (Cocoon's controller written in server-side JavaScript)? Simple: just send it back to the client.

Along the existing cocoon.sendPage("mypage"), cocoon.sendPageAndWait("myotherpage") (creates a continuation and suspends the script), let's just add a cocoon.sendObject(myObject)!

This combines the best of both worlds: powerful publication pipelines for complex page layouts, and easy web remoting for applications, by using JavaScript on both the client and server sides.


Google Base: this is only the beginning