Last active
August 29, 2015 14:11
-
-
Save NoMan2000/dd4b7d6a5fc9ac82d0ae to your computer and use it in GitHub Desktop.
This file contains 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
var isValidJSON = function isValidJSON(data) { | |
if (String(data).length === 0) { | |
return false; | |
} | |
try { | |
var o = JSON.parse(data); | |
// if o checks for null, empty, or undefined. | |
// typeof object and not instanceof array makes sure it's an object and not an array. | |
// the error checker does the rest. | |
if (o && typeof o === "object" && !(o instanceof Array)) { | |
return true; | |
} | |
} catch (e) { | |
return false; | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment