Rails shouldn't output invalid JSON by default

Please check out this ticket (which would explain almost everything):

So basically, Rails to_json methods produces invalid JSON out of the
box as it doesn't quote all hash keys. This is valid JSON:

  "id": 6589,
  "code": "SIN",
  "name": "Singapore"

This is not (Rails' JSON encoders do this):

  id: 6589,
  code: "SIN",
  name: "Singapore"

I'm sure many of us would like to see Rails start producing valid JSON
by default instead of having to change a module attribute. I think
it's absolutely important that Rails outputs valid JSON by default.
Would definitely be imperative prior to the Rails 2.0 release,
especially with the attempt to achieve feature parity between XML and
JSON for encoding, decoding and serialization (see changesets
http://dev.rubyonrails.org/changeset/7519 and http://dev.rubyonrails.org/changeset/7518).

If there's a historical reason for it, can someone shed some light?
Worst case is that Rails 2.0 goes out with a big fat JSON warning
about the invalid JSON by default :wink:

Oh and the easiest solution: set
  ActiveSupport::JSON.unquote_hash_key_identifiers = false
by default in ActiveSupport::JSON (http://dev.rubyonrails.org/browser/

Chu Yeow

I support this +1

Hey eggie,

You'd be glad to know that this has been fixed! :slight_smile: Edge Rails (and
Rails 2.0) will emit valid JSON by default now.

Chu Yeow