# JSON output format

**URL:** <https://www.ruby-forum.com/t/json-output-format/173682>\
**Category:** Rails\
**Created:** [August 13, 2009, 9:49am UTC](https://www.ruby-forum.com/t/json-output-format/173682 "2009-08-13T09:49:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsdickerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/34f0e0/32.png) [@wsdickerson](https://www.ruby-forum.com/u/wsdickerson)\
**Post date:** [August 13, 2009, 9:49am UTC](https://www.ruby-forum.com/t/json-output-format/173682/1 "2009-08-13T09:49:31Z")

</div>

Hi Everyone,

I am a Rails newbie. I got a minor question about the JSON format  
produced by to\_json method.

currently my code @events.to\_json (:only =\>  
[:id , :title, :start, :end]) will produce the output :

[{“event”: {“title”: “Dissect”, “id”: 996332877, “end”:  
“2009-07-27T17:46:10Z”, “start”: “2009-07-27T15:46:10Z”}}, {“event”:  
{“title”: “Operation”, “id”: 953125641, “end”: “2009-07-27T14:46:10Z”,  
“start”: “2009-07-27T12:46:10Z”}}]

but I want the format of the JSON output like

[{“title”: “Dissect”, “id”: 996332877, “end”: “2009-07-27T17:46:10Z”,  
“start”: “2009-07-27T15:46:10Z”},{“title”: “Operation”, “id”:  
953125641, “end”: “2009-07-27T14:46:10Z”, “start”:  
“2009-07-27T12:46:10Z”}]

how can I remove the unnecessary “event” atttribute?

Any help will be greatly appreciated

Regards,

w.d.

---

<div class="post-metadata">

**Author:** ![wsdickerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/34f0e0/32.png) [@wsdickerson](https://www.ruby-forum.com/u/wsdickerson)\
**Post date:** [August 13, 2009, 10:10am UTC](https://www.ruby-forum.com/t/json-output-format/173682/2 "2009-08-13T10:10:36Z")

</div>

On Aug 13, 3:38 am, “w.d.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> {“title”: “Operation”, “id”: 953125641, “end”: “2009-07-27T14:46:10Z”,  
> “start”: “2009-07-27T12:46:10Z”}}]
> 
> but I want the format of the JSON output like
> 
> [{“title”: “Dissect”, “id”: 996332877, “end”: “2009-07-27T17:46:10Z”,  
> “start”: “2009-07-27T15:46:10Z”},{“title”: “Operation”, “id”:  
> 953125641, “end”: “2009-07-27T14:46:10Z”, “start”:  
> “2009-07-27T12:46:10Z”}]
> 
> how can I remove the unnecessary “event” atttribute?

If you look in the new\_rails\_defaults.yml file there is a setting that  
controls this.

Fred
