Answers for "how to validate json response to valid object javascript"

PHP
8

if json valide js

function IsJsonString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
Posted by: Guest on April-10-2020
-1

javascript is valid json string

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 validate json response to valid object javascript"

Browse Popular Code Answers by Language