Created
July 11, 2013 14:03
-
-
Save tracend/5975713 to your computer and use it in GitHub Desktop.
Underscore Mixin - isJSON : checking if a string is a valid JSON #underscore #js #cc
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
_.mixin({ | |
isJSON: function(str) { | |
try { | |
JSON.parse(str); | |
} catch (e) { | |
return false; | |
} | |
return true; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_.isJSON(20) should return true or false?