Update to LighthousePro/JSON/Spry Post

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.)

Comments

ah nice, good to know! thanks ray!
# Posted By Chris H | 7/4/07 4:05 AM
Yeah, likewise. That is a good nugget to know.
# Posted By Sam Farmer | 7/4/07 9:59 AM
Hey Ray, I know you had made some samples, etc using the PagedView functions of Spry and I had built some stuff based on your examples. I recently changed my stuff to use the JSON dataset instead of XML. The grid works fine, the sorting works fine, but the paging doesn't work at all. I posted the code on the labs forum and the guys there don't see anything that looks wrong with the code, so I was just wondering if you had tried using json in combination with paging with any success yet?
# Posted By Will | 7/18/07 6:58 PM
Hmmm. Are you doing paging with JS, or using PagedDataSets?
# Posted By Raymond Camden | 7/18/07 8:51 PM