aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
authorBrian Lopez <seniorlopez@gmail.com>2009-05-17 10:37:30 -0500
committerJoshua Peek <josh@joshpeek.com>2009-05-17 10:37:52 -0500
commit53dda29f8b34073a4b135ee224c1d09c1f10de02 (patch)
tree4046b55b7609e20c6ef4cc8732724b774b997bf8 /activesupport/lib/active_support/json
parent344ee681d6a89ea1da71c39e75c29e0cbda44914 (diff)
downloadrails-53dda29f8b34073a4b135ee224c1d09c1f10de02.tar.gz
rails-53dda29f8b34073a4b135ee224c1d09c1f10de02.tar.bz2
rails-53dda29f8b34073a4b135ee224c1d09c1f10de02.zip
Add support for parsing XML and JSON from an IO as well as a string [#2659 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/backends/jsongem.rb5
-rw-r--r--activesupport/lib/active_support/json/backends/yaml.rb5
2 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json/backends/jsongem.rb b/activesupport/lib/active_support/json/backends/jsongem.rb
index de847e30a3..d1a1cdd7d7 100644
--- a/activesupport/lib/active_support/json/backends/jsongem.rb
+++ b/activesupport/lib/active_support/json/backends/jsongem.rb
@@ -6,8 +6,11 @@ module ActiveSupport
module JSONGem
extend self
- # Converts a JSON string into a Ruby object.
+ # Parses a JSON string or IO and convert it into an object
def decode(json)
+ if json.respond_to?(:read)
+ json = json.read
+ end
data = ::JSON.parse(json)
if ActiveSupport.parse_json_times
convert_dates_from(data)
diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb
index c7db508c23..1c18fc4801 100644
--- a/activesupport/lib/active_support/json/backends/yaml.rb
+++ b/activesupport/lib/active_support/json/backends/yaml.rb
@@ -9,8 +9,11 @@ module ActiveSupport
module Yaml
extend self
- # Converts a JSON string into a Ruby object.
+ # Parses a JSON string or IO and converts it into an object
def decode(json)
+ if json.respond_to?(:read)
+ json = json.read
+ end
YAML.load(convert_json_to_yaml(json))
rescue ArgumentError => e
raise ParseError, "Invalid JSON string"