Skip to content

Instantly share code, notes, and snippets.

@raspo
Created July 23, 2013 10:21
Show Gist options
  • Save raspo/6061387 to your computer and use it in GitHub Desktop.
Save raspo/6061387 to your computer and use it in GitHub Desktop.
Simple and easy way to validate a JSON string. Will need json2.js for cross-browser support.
function isValidJson(json){
try {
JSON.parse(json);
return true;
} catch (e) {
return false;
}
}
// usage
console.log(isValidJson("{}")); // true
console.log(isValidJson("abc")); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment