Rails, what were you thinking? You went and wrote your own ridiculous JSON serializer in pure Ruby, when a perfectly good C-extension gem already does the job 20 times faster. What’s worse, you gave your to_json method (which clobbers every innocent object it can get its grubby little hands on) a completely incompatible method signature from the standard gem version. You just can’t mix the two, which is ALL KINDS OF FUN for those of us who need to push more than 10 reqs/sec.
Then there’s awesome behavior like this:
<cr:code lang=“ruby”> puts {:rails => /fail/x}.to_json #=> {“rails” => /fail/x} </cr:code>
That’s not even valid ECMAScript, let alone JSON. It’s a standard for a reason, foo! It’s not like you can opt out, either. You’re stuck with this pathologically malingering monkeypatch any time you require ActiveSupport.
At least they figured it out eventually.
They did not figure it out completely. It encodes some characters incorrectly:
Loading development environment (Rails 2.3.5)
For reference:
irb(main):001:0> require ‘json’ => true irb(main):002:0> JSON::dump(["foo\001bar”]) => “[\"foo\u0001bar\”]“