Set data to undefined instead of an empty object
Only attempt to stringify JSON if data is not undefined