Class: MultiJson::Adapters::JsonGem
- Inherits:
-
MultiJson::Adapter
- Object
- MultiJson::Adapter
- MultiJson::Adapters::JsonGem
- Defined in:
- lib/multi_json/adapters/json_gem.rb
Overview
Use the JSON gem to dump/load.
Constant Summary collapse
- ParseError =
::JSON::ParserError
Instance Method Summary collapse
Methods inherited from MultiJson::Adapter
Methods included from Options
#default_dump_options, #default_load_options, #dump_options, #dump_options=, #load_options, #load_options=
Instance Method Details
#dump(object, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/multi_json/adapters/json_gem.rb', line 27 def dump(object, = {}) opts = .dup if opts.delete(:pretty) opts = PRETTY_STATE_PROTOTYPE.merge(opts) return ::JSON.pretty_generate(object, opts) end ::JSON.generate(object, opts) end |
#load(string, options = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/multi_json/adapters/json_gem.rb', line 20 def load(string, = {}) string = string.dup.force_encoding(Encoding::UTF_8) if string.encoding != Encoding::UTF_8 [:symbolize_names] = true if .delete(:symbolize_keys) ::JSON.parse(string, ) end |