Files
DB-GPT/web/utils/json.ts
aries_ckt bbf270699a Merge branch 'feature/support-neo4j' into feat/dbgpt_skill
# 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
2026-02-12 17:43:17 +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;
}
}