Something like:
var jsonString = \'{ \"Id\": 1, \"Name\": \"Coke\" }\'; //should be true IsJsonString(jsonString); //should be false IsJsonString(\"foo\");
Here is the typescript version too:
JSONTryParse(input: any) { try { //check if the string exists if (input) { var o = JSON.parse(input); //validate the result too if (o && o.constructor === Object) { return o; } } } catch (e: any) { } return false; };