I think a good way to produce, your JSON objects is with Jbuilder, because in this way you don’t have to override the “as_json” method. Then if you have a template that returns JSON, you can render it in your view.
json.array!(@milestones) do |json, milestone| json.(milestone, :id, :name, :due_date) json.tasks milestone.tasks end