Created
July 23, 2013 10:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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