Module: ActiveSupport::JSON

Defined in:
lib/active_support/json/decoding.rb,
lib/active_support/json/encoding.rb,
lib/active_support/json/variable.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
19
20
21
22
23
24
# File 'lib/active_support/json/decoding.rb', line 11

def decode(json, options ={})
  # Can't reliably detect whether MultiJson responds to load, since it's
  # a reserved word. Use adapter as a proxy for new features.
  data = if MultiJson.respond_to?(:adapter)
    MultiJson.load(json, options)
  else
    MultiJson.decode(json, options)
  end
  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 '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



26
27
28
29
30
31
32
# File 'lib/active_support/json/decoding.rb', line 26

def engine
  if MultiJson.respond_to?(:adapter)
    MultiJson.adapter
  else
    MultiJson.engine
  end
end

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



35
36
37
38
39
40
41
# File 'lib/active_support/json/decoding.rb', line 35

def engine=(name)
  if MultiJson.respond_to?(:use)
    MultiJson.use name
  else
    MultiJson.engine = name
  end
end

.parse_errorObject



51
52
53
# File 'lib/active_support/json/decoding.rb', line 51

def parse_error
  MultiJson::DecodeError
end

.with_backend(name) ⇒ Object



44
45
46
47
48
49
# File 'lib/active_support/json/decoding.rb', line 44

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