Module: ActiveSupport::JSON

Defined in:
lib/gems/activesupport-2.2.2/lib/active_support/json/decoding.rb,
lib/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb,
lib/gems/activesupport-2.2.2/lib/active_support/json/variable.rb,
lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/string.rb

Defined Under Namespace

Modules: Encoding Classes: CircularReferenceError, ParseError, Variable

Constant Summary collapse

REFERENCE_STACK_VARIABLE =

:nodoc:

:json_reference_stack

Class Method Summary collapse

Class Method Details

.decode(json) ⇒ Object

Converts a JSON string into a Ruby object.



11
12
13
14
15
# File 'lib/gems/activesupport-2.2.2/lib/active_support/json/decoding.rb', line 11

def decode(json)
  YAML.load(convert_json_to_yaml(json))
rescue ArgumentError => e
  raise ParseError, "Invalid JSON string"
end

.encode(value, options = {}) ⇒ Object

Converts a Ruby object into a JSON string.



19
20
21
22
23
# File 'lib/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb', line 19

def encode(value, options = {})
  raise_on_circular_reference(value) do
    value.send(:to_json, options)
  end
end