You can create a method to do the checking:
def valid_json?(json)
JSON.parse(json)
true
rescue JSON::ParserError, TypeError => e
false
end
You can create a method to do the checking:
def valid_json?(json)
JSON.parse(json)
true
rescue JSON::ParserError, TypeError => e
false
end