String serializer in javascript