Files
30-seconds-of-code/snippets/isValidJSON.md
2017-12-31 15:01:34 +02:00

295 B

isValidJSON

Checks if the provided argument is a valid JSON.

Use JSON.parse() and a try... catch block to check if the provided argument is a valid JSON.

const arr = (obj) => {
  try{
    JSON.parse(obj);
    return true;
  }
  catch(e){
    return false;
  }
}