Created
August 24, 2014 15:56
-
-
Save jeffjohnson9046/044a63f46153ba2b02b7 to your computer and use it in GitHub Desktop.
A quick and dirty way to tell if the data received in a response can be parsed as JSON.
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
def valid_json?(data) | |
JSON.parse(data) | |
return true | |
rescue JSON::ParserError | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment