Skip to content

Instantly share code, notes, and snippets.

@scpedicini
Created December 20, 2020 18:12
Show Gist options
  • Save scpedicini/9b7fa81c33246694797843d69aad468e to your computer and use it in GitHub Desktop.
Save scpedicini/9b7fa81c33246694797843d69aad468e to your computer and use it in GitHub Desktop.
Convert a JSON string into a standard javascript object
/**
* 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