Forum: Ruby on Rails to_json delivers incorrect format? Anyone else seeing this?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
33a61362b1a372f38731719cda90c101?d=identicon&s=25 JJ_RoR (Guest)
on 2007-05-31 14:20
(Received via mailing list)
@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 }

Am I missing something?
This topic is locked and can not be replied to.