JSON Compression

JSON Compression

prathapprathap Posts: 11Questions: 1Answers: 0

Dear Alan,

Right now, am using JSON object array, which returns data in the following format.

$('#JsonDialString').dataTable({
"sAjaxSource": '/Dials/GetDialJSON/',
"sPaginationType": "full_numbers",
"bDeferRender": true,
"bDestroy": true,
"bRetrieve": true,
"aaSorting": [[1, "asc"]],
"aoColumns": [
{"mData": "MaxLength","sTitle": "Max Length","sWidth": "10%" },....
]
.......

This returns around 40k records in the following format, which takes around 15 - 20 sec to load in data table. While investigating, we found the JSON file size is large around 7MB to 10MB.

{ "aaData": [{ id: 12, score: 34, interval: 5678, sub: 9012}, { id: 98, score: 76, interval: 5432, sub: 1098}, ...]}

This is because headings (id,score,interval, sub) repeat that much making the size huge like 7MB - 10MB.

Is there any option to keep the format in such a way that headings (id, score,interval,sub) repeat once only. Something like below.

[["id","score","interval","sub"],12,34,5678,9012,98,76,5432,1098,...]
or
{
“id”: [“12”, “98”],
“score”: [“34”, “76”],
“interval”: [“5678”, “5432”],
“sub”: [“9012”, “1098”],
}
or
any other option in datatable to compress json.

Thanks,
Prathap.

Answers

  • allanallan Posts: 54,900Questions: 1Answers: 8,605 Site admin

    You could use an array, then you don't need the labels at all. The other option is to do something like you suggest, with array to object mapping information in the object, and then transform it in the browser, but that will be a performance hit as well. You'll be better off with a simple array.

    Allan

  • prathapprathap Posts: 11Questions: 1Answers: 0

    Alan,

    Thank you for your reply.

    Earlier we were using array. But then we were not able to map stored procedure field names to values. So changed to object array to use mData. If am using array of array rather than object array will i be able to use mData? As i have to map stored procedure field names with values rather than using index of aoColumns.

    Kindly reply.

    Regards,
    Prathap

  • allanallan Posts: 54,900Questions: 1Answers: 8,605 Site admin

    If am using array of array rather than object array will i be able to use mData?

    Sure. But obviously you would only be able to use the array indexes, since there are no object properties.

    A guess another option is to reduce the size of your object property names. But the minimum size, if you want that, will only be achieved with arrays.

    Allan

  • prathapprathap Posts: 11Questions: 1Answers: 0

    Allan,

    Thanks for your comments.

    That is the main issue, why we are using object array as we dont need array indexes as there will be change in the field orders in stored procedures now and then. Then every time, we need to check in the coding side also.

    Do you have any idea on JSON compression by using GZip or something like that which can be included in datatables?

    Regards,
    Prathap.

  • allanallan Posts: 54,900Questions: 1Answers: 8,605 Site admin

    If you haven't already, then enable gzip in your web-server. It isn't something that would go into DataTables as it is handled by the browser and server, but it will make a significant difference if you haven't already got it enabled.

    Allan

  • prathapprathap Posts: 11Questions: 1Answers: 0

    Thanks allan for your feedbacks.I will make a try.

    Regards,
    Prathap.

This discussion has been closed.