parse a string as json js code example
Example 1: if json then parse
function isJson(str) {
try {
let value = JSON.parse(str);
return value
} catch (e) {
return str;
}
}
Example 2: javascript parse json
const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);