Yesterday I blogged about how I moved Lighthouse Pro over to JSON using CFJSON and Spry. In general it worked nice and gave me some size savings on the data, but I had run into one problem.

The format of the data returned from CFJSON wasn't working right with Spry. I had to tell CFJSON to return it's data in "array" format. This gave me data that looked like so (and by the way, this is borrowed from the Spry docs that I'll be linking to in a moment):

{ "data": [ { "firstname": "John", "lastname": "Smith", "id": "3001" }, { "firstname": "Jane", "lastname": "Doe", "id": "4532" }, { "firstname": "Ann", "lastname": "Hunt", "id": "5462" } ] }

Turns out though - that Spry had built in support for the default way that CFJSON returned cfqueries. Why? The default way CFJSON returns queries is actually even smaller. Consider this version:

{ "data": { "firstname": [ "John", "Jane", "Ann" ], "lastname": [ "Smith", "Doe", "Hunt" ] "id": [ "3001", "4532", "5462" ] } }

Notice that the main change is the columns are not repeated. In order for Spry to work with this form, I simply had to add a new attribute to my JSONDataSet creation:

var dsIssues = new Spry.Data.JSONDataSet("issuesxml.cfm?id=#p.getID()#&stupid=#rand("SHA1PRNG")#",{path:"data", pathIsObjectOfArrays: true});

Note specifically the pathIsObjectOfArray attribute.

Ok - so why is this a big deal? Well as I mentioned in the last post, I had hoped the savings in size would be a bit better. For my 300 issue project I went from 130k to 90k. Guess what the size was for this alternate version? 40k. Now that is a nice savings.

For more information on the options concerning JSON datasets in Spry, see this page. Thanks go to Kin Blas of Adobe for pointing this out to me. (And Lighthouse Pro users will see this in the zip later today.)