move the JSON.parse to the beginning of email parsing