Files
DB-GPT/web/utils/json.ts
Aries-ckt ef83851b31 🎉 DB-GPT V0.8.0 - Beta Testing (#2988)
Co-authored-by: lusain <lusain1990@gmail.com>
Co-authored-by: alan.cl <1165243776@qq.com>
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-03-16 11:55:42 +08:00

13 lines
319 B
TypeScript

/**
* Utility function to safely parse JSON strings.
* When parsing fails, it returns a default value or null.
*/
export function safeJsonParse<T>(jsonString: string, def: T): T {
try {
return JSON.parse(jsonString);
} catch (error) {
console.error('Failed to parse JSON:', error);
return def;
}
}