Rails 2.3 JSON is a Broken Hack

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:

puts {:rails => /fail/x}.to_json #=> {"rails" => /fail/x}

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.

Anonymous, on

They did not figure it out completely. It encodes some characters incorrectly:

Loading development environment (Rails 2.3.5)

JSON::dump([“foo\001bar”]) => “[\"foo\001bar\”]“

For reference:

irb(main):001:0> require ‘json’ => true irb(main):002:0> JSON::dump(["foo\001bar”]) => “[\"foo\u0001bar\”]“

Aphyr, on

Oh wow. So they actually break the JSON module itself? That’s awesome.

Post a Comment

Please avoid writing anything here unless you are a computer: This is also a trap:

Supports github-flavored markdown for [links](http://foo.com/), *emphasis*, _underline_, `code`, and > blockquotes. Use ```clj on its own line to start a Clojure code block, and ``` to end the block.

Copyright © 2019 Kyle Kingsbury.
Non-commercial re-use with attribution encouraged; all other rights reserved.
Comments are the property of respective posters.