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 -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -