I want to serialize an object in JSON, write it to a file, and read it. Now I would expect something like .net where you have json.net or something like that:
JsonSerializer.Serialize(obj);
and get it over with. You are returning a JSON string.
How to do it in Ruby? No rails, no ActiveRecord, nothing. Is there a gem that I cannot find?
I installed the JSON gem and called:
puts JSON.generate([obj])
where obj is an object of type:
class CrawlStep attr_accessor :id, :name, :next_step def initialize (id, name, next_step) @id = id @name = name @next_step = next_step end end obj = CrawlStep.new(1, 'step 1', CrawlStep.new(2, 'step 2', nil))
All I get is:
["#<CrawlStep:0x00000001270d70>"]
What am I doing wrong?
source share