Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

235 B
Raw Blame
export const safeParseJSON = <T = Record<string, any>>(text?: string) => {
  if (typeof text !== 'string') return undefined;

  let json: T;
  try {
    json = JSON.parse(text);
  } catch {
    return undefined;
  }

  return json;
};