Last active
September 27, 2017 20:57
-
-
Save bcls/f3cdc605c3aae67388b221481aa7acb0 to your computer and use it in GitHub Desktop.
is this string JSON? #javascript
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
/* | |
* tests to see if a string is json | |
* @param {String} str string to test | |
* @return {Boolean} | |
*/ | |
function isJson(str) { | |
try { | |
JSON.parse(str); | |
} catch (e) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment