Something like:
var jsonString = \'{ \"Id\": 1, \"Name\": \"Coke\" }\'; //should be true IsJsonString(jsonString); //should be false IsJsonString(\"foo\");
If you're dealing with a response from an AJAX (or XMLHttpRequest) call, what worked for me is to check the response content type and parse or not the content accordingly.