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, 10 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index 0e079341ff..70e9f40fc7 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -1,5 +1,4 @@
-require 'yaml'
-require 'strscan'
+require 'active_support/core_ext/string/starts_ends_with'
module ActiveSupport
module JSON
@@ -20,7 +19,8 @@ module ActiveSupport
# Ensure that ":" and "," are always followed by a space
def convert_json_to_yaml(json) #:nodoc:
- scanner, quoting, marks, pos, times = StringScanner.new(json), false, [], nil, []
+ require 'strscan' unless defined? ::StringScanner
+ scanner, quoting, marks, pos, times = ::StringScanner.new(json), false, [], nil, []
while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
case char = scanner[1]
when '"', "'"
@@ -45,7 +45,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 +61,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 = {})