how to check if string is JSON string or not in JS 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: check if the data can be parsed javascript
function isJson(str) {
try {
return JSON.parse(str);
} catch (e) {
return false;
}
}