title: How to customize json output in rails?
body: <p>I have a model for languages and i want to get all the languages as json but the json output looks as follows </p>
  
  <blockquote>
    <p>[{"language":{"created_at":null,"id":1,"language":"English","updated_at":null}},{"language":{"created_at":null,"id":2,"language":"Swedish","updated_at":null}},{"language":{"created_at":null,"id":3,"language":"German","updated_at":null}},{"language":{"created_at":null,"id":4,"language":"French","updated_at":null}},{"language":{"created_at":null,"id":5,"language":"spanish","updated_at":null}},{"language":{"created_at":null,"id":6,"language":"dutch","updated_at":null}},{"language":{"created_at":"2012-12-03T05:01:18Z","id":7,"language":"Tamil","updated_at":"2012-12-03T05:01:18Z"}}]</p>
  </blockquote>
  
  <p>but i want to make this as</p>
  
  <blockquote>
    <p>{"language":[{"created_at":null,"id":1,"language":"English","updated_at":null},{"created_at":null,"id":2,"language":"Swedish","updated_at":null},{"created_at":null,"id":3,"language":"German","updated_at":null},{"created_at":null,"id":4,"language":"French","updated_at":null},{"created_at":null,"id":5,"language":"spanish","updated_at":null},{"created_at":null,"id":6,"language":"dutch","updated_at":null},{"created_at":null,"id":7,"language":"Tamil","updated_at":null} ] }</p>
  </blockquote>
  
  <p><strong>Update</strong></p>
  
  <pre><code>def index
   @languages = Language.all
   respond_to do |format|
     format.json { render json: @languages}
   end
  end
  </code></pre>
  
  <p><strong>update 2</strong></p>
  
  <pre><code>    class Language &lt; ActiveRecord::Base
          ActiveRecord::Base.include_root_in_json = false
          has_and_belongs_to_many :users 
      end
  </code></pre>