Created
December 20, 2020 18:12
-
-
Save scpedicini/9b7fa81c33246694797843d69aad468e to your computer and use it in GitHub Desktop.
Convert a JSON string into a standard javascript object
This file contains hidden or 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
/** | |
* Convert a JSON string into a standard Javascript Object | |
* @param x - JSON string | |
* @returns {{}} - Deserialized object or empty object | |
*/ | |
static SafeParse(x) { | |
let obj = { }; | |
try | |
{ | |
if(x !== null && x !== undefined) | |
obj = JSON.parse(x); | |
} | |
catch (e) | |
{ | |
obj = { }; | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment