Add equivalent serialize() function (based on phpjs version)