@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?