Valid JSON from Rails

By default Ruby on Rails emits invalid JSON when you use the to_json method. Most of the libraries Rails devs are using to parse JSON, e.g. jQuery or Prototype, work fine with the “invalid” JSON but the JSON Ruby library doesn’t. It requires valid JSON.

Thankfully it is pretty easy to tell Rails to emit valid JSON. Just set ActiveSupport::JSON.unquote_hash_key_identifiers = false in your environment.rb.

Viewing 4 Comments

Trackbacks

close Reblog this comment
blog comments powered by Disqus