Module: ActiveSupport::JSON

Defined in:
activesupport/lib/active_support/json/encoding.rb,
activesupport/lib/active_support/json/variable.rb,
activesupport/lib/active_support/json/decoding.rb

Defined Under Namespace

Modules: Encoding Classes: Variable

Constant Summary collapse

DATE_REGEX =

matches YAML-formatted dates

/^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
CircularReferenceError =
Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)

Class Method Summary collapse

Class Method Details

.decode(json, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'activesupport/lib/active_support/json/decoding.rb', line 11

def decode(json, options ={})
  data = MultiJson.decode(json, options)
  if ActiveSupport.parse_json_times
    convert_dates_from(data)
  else
    data
  end
end

.encode(value, options = nil) ⇒ Object

Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.



30
31
32
# File 'activesupport/lib/active_support/json/encoding.rb', line 30

def self.encode(value, options = nil)
  Encoding::Encoder.new(options).encode(value)
end

.engineObject Also known as: backend



20
21
22
# File 'activesupport/lib/active_support/json/decoding.rb', line 20

def engine
  MultiJson.engine
end

.engine=(name) ⇒ Object Also known as: backend=



25
26
27
# File 'activesupport/lib/active_support/json/decoding.rb', line 25

def engine=(name)
  MultiJson.engine = name
end

.parse_errorObject



37
38
39
# File 'activesupport/lib/active_support/json/decoding.rb', line 37

def parse_error
  MultiJson::DecodeError
end

.with_backend(name) ⇒ Object



30
31
32
33
34
35
# File 'activesupport/lib/active_support/json/decoding.rb', line 30

def with_backend(name)
  old_backend, self.backend = backend, name
  yield
ensure
  self.backend = old_backend
end