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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -