module ActiveSupport::JSON

Constants

CircularReferenceError
DATE_REGEX

matches YAML-formatted dates

DECODERS

Listed in order of preference.

Attributes

parse_error[R]

Public Class Methods

backend() click to toggle source
# File lib/active_support/json/decoding.rb, line 16
def backend
  set_default_backend unless defined?(@backend)
  @backend
end
backend=(name) click to toggle source
# File lib/active_support/json/decoding.rb, line 21
def backend=(name)
  if name.is_a?(Module)
    @backend = name
  else
    require "active_support/json/backends/#{name.to_s.downcase}"
    @backend = ActiveSupport::JSON::Backends::const_get(name)
  end
  @parse_error = @backend::ParseError
end
encode(value, options = nil) click to toggle source

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

# File lib/active_support/json/encoding.rb, line 29
def self.encode(value, options = nil)
  Encoding::Encoder.new(options).encode(value)
end
set_default_backend() click to toggle source
# File lib/active_support/json/decoding.rb, line 38
def set_default_backend
  DECODERS.find do |name|
    begin
      self.backend = name
      true
    rescue LoadError
      # Try next decoder.
      false
    end
  end
end
with_backend(name) { || ... } click to toggle source
# File lib/active_support/json/decoding.rb, line 31
def with_backend(name)
  old_backend, self.backend = backend, name
  yield
ensure
  self.backend = old_backend
end