I’m not a Ruby guy, I just play one on television. I have to modify someone’s old Cron job to pull down some JSON and convert it into objects.
Here’s the code
raw_json = Net::HTTP.get(URI.parse("url removed to protect the innocent"))
tags = ActiveSupport::JSON.decode(raw_json)
puts tags.count
tags.count will accurately trace as 5, but THAT LINE immediately causes a crash as follows:
5 #the accurate count!
rake aborted!
undefined method `count' for false:FalseClass
What is the dealio?
What is the contents of
raw_json? What appears to be happening is thatActiveSupport::JSON#decodeis returning false (henceundefined method 'count' for false:FalseClass). I thinkJSON#decodeonly returns false when given an empty string, which would meanHTTP#getis returning an empty string. Check onraw_jsonand see if it contains what you expect.