in customer-support-agent/app/api/chat/route.ts [198:210]
function sanitizeAndParseJSON(jsonString : string) {
// Replace newlines within string values
const sanitized = jsonString.replace(/(?<=:\s*")(.|\n)*?(?=")/g, match =>
match.replace(/\n/g, "\\n")
);
try {
return JSON.parse(sanitized);
} catch (parseError) {
console.error("Error parsing JSON response:", parseError);
throw new Error("Invalid JSON response from AI");
}
}