class MultiJson::Adapters::JsonGem

Use the JSON gem to dump/load.

def dump(object, options = {})

Other tags:
    Example: Serialize object to JSON -

Returns:
  • (String) - JSON string

Parameters:
  • options (Hash) -- serialization options
  • object (Object) -- object to serialize

Other tags:
    Api: - private
def dump(object, options = {})
  opts = options.except(:adapter)
  json_object = object.respond_to?(:as_json) ? object.as_json : object
  return ::JSON.dump(json_object) if opts.empty?
  if opts.delete(:pretty)
    opts = PRETTY_STATE_PROTOTYPE.merge(opts)
    return ::JSON.pretty_generate(json_object, opts)
  end
  ::JSON.generate(json_object, opts)
end

def load(string, options = {})

Other tags:
    Example: Parse JSON string -

Returns:
  • (Object) - parsed Ruby object

Parameters:
  • options (Hash) -- parsing options
  • string (String) -- JSON string to parse

Other tags:
    Api: - private
def load(string, options = {})
  string = string.dup.force_encoding(Encoding::UTF_8) if string.encoding != Encoding::UTF_8
  options[:symbolize_names] = true if options.delete(:symbolize_keys)
  ::JSON.parse(string, options)
end