Q:

Write a JavaScript program to check if the provided argument is a valid JSON

0

Write a JavaScript program to check if the provided argument is a valid JSON.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const isValidJSON = obj => {
  try {
    JSON.parse(obj);
    return true;
  } catch (e) {
    return false;
  }
};
console.log(isValidJSON('{"name":"Adam","age":20}'));
console.log(isValidJSON('{"name":"Adam",age:"20"}'));
console.log(isValidJSON(null));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now