Parse.js code example
Example 1: javascript parse json
var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson);
Example 2: if json then parse
function isJson(str) {
try {
let value = JSON.parse(str);
return value
} catch (e) {
return str;
}
}
Example 3: javascript parse json
const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
Example 4: js parse json
const json = '{"result":true, "count":42}';
const obj = JSON.parse(json);
console.log(obj.count);
console.log(obj.result);