aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/json/encoders/hash.rb
blob: 3654e10b2e2ed7831402294617cebc0bf3d12005 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                                  
class Hash
  def to_json #:nodoc:
    returning result = '{' do
      result << map do |key, value|
        key = ActiveSupport::JSON::Variable.new(key.to_s) if 
          ActiveSupport::JSON.can_unquote_identifier?(key)
        "#{ActiveSupport::JSON.encode(key)}: #{ActiveSupport::JSON.encode(value)}"
      end * ', '
      result << '}'
    end
  end
end