Answers for "parse a string as json js"

PHP
1

if json then parse

function isJson(str) {
    try {
        let value = JSON.parse(str);
      	return value
    } catch (e) {
        return str;
    }
}
Posted by: Guest on November-03-2020
12

javascript parse json

const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
Posted by: Guest on May-20-2020

Browse Popular Code Answers by Language