Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4612

Checking if a string is valid json before trying to parse it?

$
0
0

In Ruby, is there a way to check if a string is valid json before trying to parse it?

For example getting some information from some other urls, sometimes it returns json, sometimes it could return a garbage which is not a valid response.

My code:

def get_parsed_response(response)  parsed_response = JSON.parse(response)end

Viewing all articles
Browse latest Browse all 4612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>