aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/encoders/core.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/json/encoders/core.rb')
-rw-r--r--activesupport/lib/active_support/json/encoders/core.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json/encoders/core.rb b/activesupport/lib/active_support/json/encoders/core.rb
index d8571be9c8..f6cdfbcde5 100644
--- a/activesupport/lib/active_support/json/encoders/core.rb
+++ b/activesupport/lib/active_support/json/encoders/core.rb
@@ -51,8 +51,10 @@ module ActiveSupport
define_encoder Hash do |hash|
returning result = '{' do
- result << hash.map do |pair|
- pair.map { |value| value.to_json } * ': '
+ result << hash.map do |key, value|
+ key = ActiveSupport::JSON::Variable.new(key.to_s) if
+ ActiveSupport::JSON.can_unquote_identifier?(key)
+ "#{key.to_json}: #{value.to_json}"
end * ', '
result << '}'
end