Forum: Ruby on Rails Modifying output from to_json to exclude table name

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
skt (Guest)
on 2009-03-06 01:01
(Received via mailing list)

I have a Meal model and Model.find(:all).to_json returns the following

[{"meal": {"name": "Veggies Lasagna", "id": 1}}, {"meal": {"name":
"Chicken Rice", "id": 2}}, {"meal": {"name": "Noodle Rice", "id": 3}}]

What I want to do is not have the table name (meal) be part of the
output json string i.e. what I want it to output is

[ {"name": "Veggies Lasagna", "id": 1}, {"name": "Chicken Rice", "id":
2}, {"name": "Noodle Rice", "id": 3}]

Any way I can do this? I looked at to_json input options which seem to
let you control the columns that are output but apparently not the
table name.

If you are wondering why I need JSON output in this format, that is
because I want to consume this output from

Thanks for any pointers/help.

skt (Guest)
on 2009-03-06 01:12
(Received via mailing list)
Figured it out.

Have to set ActiveRecord::Base.include_root_in_json = false
This topic is locked and can not be replied to.