Purpose

A jQuery function that will parse the JSON returned from an ajax call to a remote ColdFusion method and recursively convert any ColdFusion query object into a standard JSON recordset, as recognized by a great number of plugins and libraries.

Standard native ColdFusion query object, as rendered by it's 'json' returnFormat:

{
    "COLUMNS":["ID","NAME","EMAIL"],
    "DATA":[
        [1,"Ed Spencer","ed@sencha.com"],
        [2,"Abe Elias","abe@sencha.com"],
        [3,"Cutter","no@address.giv"]
    ]
}

converted by the method, the output becomes

[
    {"id":1,"name":"Ed Spencer","email":"ed@sencha.com"},
    {"id":2,"name":"Abe Elias","email":"abe@sencha.com"},
    {"id":3,"name":"Cutter","email":"no@address.giv"}
]

The method will recursively trace each node of the JSON structure, and convert any object it finds with a COLUMNS and a DATA key, including those created by using the ConvertQueryForGrid() method. Note: The method will automatically lower case the column names.

Usage

var populateGrid = function (postdata) {
    $.ajax({
        url: '/com/cc/Blog/Entries.cfc',
        data: {
            method: 'GetEntries',
            returnFormat: 'json'
        },
        method:'POST',
        dataType:"json",
        success: function(d,r,o){
            d = $.serializeCFJSON(d);
            if(d.success){
                // do something with the data
            } else {
                // handle the error
            }
        }
    });
};
 

This example uses serializeCFJSON to convert the paging data requests used by an instance of jqGrid.

Demo


To search for entries on a specific date, use the To field only.