# To\_json delivers incorrect format? Anyone else seeing this?

**URL:** <https://www.ruby-forum.com/t/to-json-delivers-incorrect-format-anyone-else-seeing-this/105589>\
**Category:** Rails\
**Created:** [May 31, 2007, 2:20pm UTC](https://www.ruby-forum.com/t/to-json-delivers-incorrect-format-anyone-else-seeing-this/105589 "2007-05-31T14:20:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JJ\_RoR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@JJ\_RoR](https://www.ruby-forum.com/u/JJ_RoR)\
**Post date:** [May 31, 2007, 2:20pm UTC](https://www.ruby-forum.com/t/to-json-delivers-incorrect-format-anyone-else-seeing-this/105589/1 "2007-05-31T14:20:06Z")

</div>

@notes.to\_json outputs=\> [  
{attributes: {title: “My Shiny New Box”, individual\_id: “1”, id: “1”,  
note: “The first of many such things”}},  
{attributes: {title: “A second box”, individual\_id: “2”, id: “2”,  
note: “This is the second in a series of notes describing a box”}}  
]

The keys (e.g. title:) are not quoted. I see this on my local dev and  
on the main server.

Feeding this string back through the JSON::parser.decode(jsonstring)  
fails with an ‘unexpected token’ error.

Quoting the keys works fine.

An example json string from Wikipedia shows the keys quoted:

{  
“firstName”: “John”,  
“lastName”: “Smith”,  
“address”: {  
“streetAddress”: “21 2nd Street”,  
“city”: “New York”,  
“state”: “NY”,  
“postalCode”: 10021  
},  
“phoneNumbers”: [  
“212 732-1234”,  
“646 123-4567”  
]  
}

The code in the controller is:

def index  
@notes = Note.find(:all)  
respond\_to do |format|  
format.html # index.rhtml  
format.xml { render :xml =\> @notes.to\_xml }  
format.json { render :json =\> @notes.to\_json }  
end  
end

Am I missing something?
