ruby - How to read/write a collection of objects as json -
i have collection of user classes want save json file.
users = [] users << user.new('john', 'smith', 55) file.open("users.json", "w") |f| f.write(json.pretty_generate(users) end
the problem user isn't being json'ified, saving file like:
[ "#<user:0x000000101010eff40>", .. ]
also, how read json file collection?
the problem is, users variable still array of activerecord objects. need convert them json.
users = [] users << user.new('john', 'smith', 55) file.open("users.json", "w") |f| f.write(json.pretty_generate(users.to_json) end
Comments
Post a Comment