value How to check in node.js if variable is JSON object?



json.parse nodejs (1)

I have variable for example

var x = "this is X value";

How to check in node.js if variable is JSON object ?


Your question is not clear, but assuming you meant to check if a variable has an unparsed JSON string:

try {
    JSON.parse(x);
} catch (e) {
    console.log("not JSON");
}




node.js