aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/decoding.rb12
-rw-r--r--activesupport/lib/active_support/json/encoders/hash.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/object.rb2
3 files changed, 11 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index 0e079341ff..c66500aa9c 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -1,5 +1,7 @@
-require 'yaml'
-require 'strscan'
+autoload :YAML, 'yaml' unless defined? YAML
+autoload :StringScanner, 'strscan' unless defined? StringScanner
+
+require 'active_support/core_ext/string/starts_ends_with'
module ActiveSupport
module JSON
@@ -45,7 +47,7 @@ module ActiveSupport
if marks.empty?
json.gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
ustr = $1
- if ustr.starts_with?('u')
+ if ustr.start_with?('u')
[ustr[1..-1].to_i(16)].pack("U")
elsif ustr == '\\'
'\\\\'
@@ -61,10 +63,10 @@ module ActiveSupport
scanner.pos = left.succ
output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
ustr = $1
- if ustr.starts_with?('u')
+ if ustr.start_with?('u')
[ustr[1..-1].to_i(16)].pack("U")
elsif ustr == '\\'
- '\\\\'
+ '\\\\'
else
ustr
end
diff --git a/activesupport/lib/active_support/json/encoders/hash.rb b/activesupport/lib/active_support/json/encoders/hash.rb
index e38b4f3e16..d87b880743 100644
--- a/activesupport/lib/active_support/json/encoders/hash.rb
+++ b/activesupport/lib/active_support/json/encoders/hash.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
class Hash
# Returns a JSON string representing the hash.
#
diff --git a/activesupport/lib/active_support/json/encoders/object.rb b/activesupport/lib/active_support/json/encoders/object.rb
index ca215d4964..0475967aee 100644
--- a/activesupport/lib/active_support/json/encoders/object.rb
+++ b/activesupport/lib/active_support/json/encoders/object.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/instance_variables'
+
class Object
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
def to_json(options = {})