mirror of
https://github.com/csunny/DB-GPT.git
synced 2026-07-17 01:58:47 +00:00
# Conflicts: # packages/dbgpt-ext/src/dbgpt_ext/storage/knowledge_graph/community/neo4j_store_adapter.py # uv.lock # web/locales/en/common.ts # web/locales/zh/common.ts # web/package-lock.json # web/yarn.lock
13 lines
319 B
TypeScript
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;
|
|
}
|
|
}
|