mudge (owner)

Revisions

gist: 221351 Download_button fork
public
Description:
A Rails initializer to use YAJL instead of ActiveSupport for JSON encoding.
Public Clone URL: git://gist.github.com/221351.git
Embed All Files: show embed
yajl.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Use YAJL instead of ActiveSupport::JSON to encode objects to JSON in Rails.
class Hash
  def to_json(options = nil)
    Yajl::Encoder.encode(as_json(options))
  end
end
 
class Array
  def to_json(options = nil)
    Yajl::Encoder.encode(as_json(options))
  end
 
  def as_json(options = nil)
    map { |value| value.as_json(options) }
  end
end
 
class Object
  def to_json(options = nil)
    Yajl::Encoder.encode(as_json(options))
  end
end