mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:50:42 +00:00
14 lines
344 B
TypeScript
14 lines
344 B
TypeScript
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
|
|
|
export function safeParseJson(value: string | null | undefined): unknown {
|
|
const trimmed = normalizeOptionalString(value);
|
|
if (!trimmed) {
|
|
return undefined;
|
|
}
|
|
try {
|
|
return JSON.parse(trimmed) as unknown;
|
|
} catch {
|
|
return { payloadJSON: value };
|
|
}
|
|
}
|