Skip to content

Instantly share code, notes, and snippets.

@gregpalaci
Created November 2, 2023 20:10
Show Gist options
  • Save gregpalaci/ec7c99dab7ca8549f40cbd1e853399ae to your computer and use it in GitHub Desktop.
Save gregpalaci/ec7c99dab7ca8549f40cbd1e853399ae to your computer and use it in GitHub Desktop.
safeJsonParse
const safeJsonParse = <T>(str: string) => {
try {
const jsonValue: T = JSON.parse(str);
return jsonValue;
} catch {
return undefined;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment