check if a string is in JSON compatible format using javascript or jquery
There is no direct way in javascript/jquery to check if a string is in JSON compatible format, but we can achieve by a small work around.
$.parseJSON(data)
is a jQuery method which is used to parse JSON compatible string to JSON.
try {
jsondata = $.parseJSON(data);
//if you reach here the it is a json compatible format
}
catch (e) {
// not JSON compatible format
}