Underscore Mixin - isJSON : checking if a string is a valid JSON #underscore #js #cc
_.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
This comment has been minimized.
_.isJSON(20) should return true or false?