Created
November 2, 2023 20:10
-
-
Save jswhisperer/ec7c99dab7ca8549f40cbd1e853399ae to your computer and use it in GitHub Desktop.
safeJsonParse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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