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

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -