Im hard pressed to store data as \'JSON\' format into my sqlite database for an rails application. I have searched for how to store data as JSON in my sqlite database but am
Tried first using 'JSON' as an data type but since SQLite had no support for 'JSON' data type it failed. Then again I performed an migration with the data type for the attribute set up as type 'string' and it started to work.
You need to generate a string from your JSON and then save that string in your database as a regular string.
require 'json'
my_hash = {:hello => "goodbye"}
puts JSON.generate(my_hash) => "{\"hello\":\"goodbye\"}"
When you need to use that JSON object, you select your json string and convert it to JSON object using:
json_object = JSON.parse(string)
You can read about JSON objects here: http://ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html