Skip to content

Instantly share code, notes, and snippets.

@bcls
Last active September 27, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcls/f3cdc605c3aae67388b221481aa7acb0 to your computer and use it in GitHub Desktop.
Save bcls/f3cdc605c3aae67388b221481aa7acb0 to your computer and use it in GitHub Desktop.
is this string JSON? #javascript
/*
* 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