json vs. serialize">

In an effort to save space for record­ing array infor­ma­tion, I usu­al­ly seri­al­ized the data. As I’m sure most devel­op­ers did as well. On a lark, I just decid­ed to check to see if seri­al­ize was sav­ing more space that encod­ing the date via JSON. In doing so I found that JSON, as sus­pect­ed, saves more space than seri­al­iz­ing the infor­ma­tion.

In my small, one array, test infor­ma­tion is as fol­lows:

  • Seri­al­ized data bytes: 320
  • JSON encod­ed bytes: 249

For those who are either rush­ing for a cal­cu­la­tor, or haven’t had their cof­fee this morn­ing and are unable to do math. That means that the JSON infor­ma­tion saved rough­ly 22% space. That’s a pret­ty sig­nif­i­cant sav­ings, or could be giv­en the infor­ma­tion encod­ed was larg­er.

That could save quite a bit of infor­ma­tion while sav­ing infor­ma­tion to data­bas­es or files. Which could, in the­o­ry, reduce serv­er load and data­base serv­er load, espe­cial­ly on shared host­ing servers.

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *