Module: ActiveSupport::JSON
- Defined in:
- lib/active_support/json/decoding.rb,
lib/active_support/json/encoding.rb,
lib/active_support/json/variable.rb,
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
-
.decode(json) ⇒ Object
Converts a JSON string into a Ruby object.
-
.encode(value, options = {}) ⇒ Object
Converts a Ruby object into a JSON string.
Class Method Details
.decode(json) ⇒ Object
Converts a JSON string into a Ruby object.
11 12 13 14 15 |
# File '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/active_support/json/encoding.rb', line 19 def encode(value, = {}) raise_on_circular_reference(value) do value.send(:to_json, ) end end |