Added checking for JSON.stringify and graceful degredation