Answers for "javascript check if json object is valid"

0

javascript check if json object is valid

//extensive check to make sure object is not of string type and not null
function isJson(item) {
    item = typeof item !== "string"
        ? JSON.stringify(item)
        : item;

    try {
        item = JSON.parse(item);
    } catch (e) {
        return false;
    }

    if (typeof item === "object" && item !== null) {
        return true;
    }

    return false;
}
Posted by: Guest on March-20-2021

Code answers related to "javascript check if json object is valid"

Code answers related to "Javascript"

Browse Popular Code Answers by Language