$:.push File.expand_path("../lib", __FILE__) require 'argonaut' @ideas = [ { :title => 'Garrett Bjerkhoel', :comments => [ { :id => 1, :author => 'Jake', :text => 'Sweet', :created_at => Time.now, :updated_at => Time.now }, { :id => 2, :author => 'Jake', :text => nil, :created_at => Time.now, :updated_at => Time.now } ] } ] json = Argonaut::Generator.new do |doc| doc.array_keys! ['ideas'] for idea in @ideas doc.ideas do |i| i.title idea[:title] for comment in idea[:comments] i.comments do |c| c.id comment[:id] c.author comment[:author] c.text comment[:text] c.created_at comment[:created_at] c.updated_at comment[:updated_at] end end end end end