Answers for "how to convert into valid json in javascript"

-1

javascript is JSON string valid

function isValidJSONString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
//usage
var personJSONString = '{"first_name":"Tony","last_name":"Hawk","age":31}';
if(isValidJSONString(personJSONString)){
 //cool we are valid, lets parse
 var person= JSON.parse(personJSONString);
}
Posted by: Guest on August-02-2019

Code answers related to "how to convert into valid json in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language