I am trying to check whether the response is valid JSON. I am making HTTParty or Restclient request to some urls and checking whether the responses returned are valid JSON?
I referred the link here. This is not working.
My code:
require 'json' def get_parsed_response(response) if not response.is_a? String or not response.valid_json? # code end end Error:
/home/user/.rvm/gems/ruby-2.1.0/gems/httparty-0.13.1/lib/httparty/response.rb:66:in `method_missing': undefined method `valid_json?' for #<HTTParty::Response:0x00000002497918> (NoMethodError)
valid_json?(response), if you put it into your code. Also, since you'll invariably try to parse the JSON after ascertaining that it is valid, you'd just be doing the same thing twice. Just parse your JSON and rescue from an error, forget aboutvalid_json?.unlessinstead of oldif not?