identify if string value of json is of dataset or string code example
Example 1: javascript check if string is json parsable
var isJsonParsable = string => {
try {
JSON.parse(string);
} catch (e) {
return false;
}
return true;
}
Example 2: if json then parse
function isJson(str) {
try {
let value = JSON.parse(str);
return value
} catch (e) {
return str;
}
}