1 require 'json' unless defined?(JSON)
2
3 module ActiveSupport
4 module JSON
5 module Backends
6 module JSONGem
7 ParseError = ::JSON::ParserError
8 extend self
9
10 # Converts a JSON string into a Ruby object.
11 def decode(json)
12 data = ::JSON.parse(json)
13 if ActiveSupport.parse_json_times
14 convert_dates_from(data)
15 else
16 data
17 end
18 end
19
20 private
21 def convert_dates_from(data)
22 case data
23 when DATE_REGEX
24 DateTime.parse(data)
25 when Array
26 data.map! { |d| convert_dates_from(d) }
27 when Hash
28 data.each do |key, value|
29 data[key] = convert_dates_from(value)
30 end
31 else data
32 end
33 end
34 end
35 end
36 end
37 end