
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
//the json is not ok
return false;
}
//the json is ok
return true;
}
Source
https://github.com/roeib/JavaScript-snippets#check-if-a-string-is-a-valid-json