Help with JSONified objects from ActiveRecord

Hello guys,

I’m trying to return a custom JSON response to a client frontend.
The object I’m trying to return is a User, with some associated Locale

So basically I need to put the User data and his Locale in a “data”
property in the JSON response.

If this worked, it would be perfect:
json =
json[:success] = false
json[:data] = User.find(params[:id], :include => :locale)
json[:success] = true
render :json => json

The example above doesn’t include the association in the returned data
(I know that include is used so ActiveRecord won’t query the DB again in
case we use the locale data).
What would I need to do to return the associated Locale data with the
User, I would like to use the approach of using a Hash, like in the
example above.

I know you can do something like this:
json = User.find(params[:id]).to_json(:include => :locale)

But that stringify the record, and I don’t see an easy way to put that
data into a JSON property and do something like this:
json =
json[:success] = false
json[:data] = User.find(params[:id]).to_json(:include => :locale)
json[:success] = true
render :json => json

That above doesn’t work, because the to_json method already put a JSON
string in json[:data].

Any suggestions?

Thanks in advance.