Having collected some JSON from a file using the Curb gem, I assign a portion of it to an instance variable:
self.json_stuff = {"title" => json["title"], "description" => json["description"], "image" => json["image"]}.to_json
This then gets stored in the database as JSON:
serialize :json_stuff, JSON
...
self.save
Later on I check for the presence of said json_stuff:
return self.json_stuff.present?
And get the following error:
TypeError - no implicit conversion of Hash into String:
json (1.8.3) lib/json/common.rb:155:in `initialize'
json (1.8.3) lib/json/common.rb:155:in `new'
json (1.8.3) lib/json/common.rb:155:in `parse'
I've stepped through the code and I know that the collection of the JSON from the file is done without issue.
p self.json_stuffprints ? Furthermore, I think you try to encode your object two times, the first one with.to_jsonwhich give you a string, and then when you save id with theserializeaction, could you try to remove.to_jsonfrom your first line ?no implicit conversion of Hash into String... I'll look in to the suggestion of it being encoded twice... Thanks for the pointer...to_jsonbut still getting the same error... When I get the json from the file, I parse it usingJSON.parse, is this correct?JSON.parsecorrectly, I mean was I right to useJSON.parseat all?