Class: MultiJSON::Adapters::Yajl Private

Inherits:
MultiJSON::Adapter show all
Defined in:
lib/multi_json/adapters/yajl.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Use the Yajl-Ruby library to dump/load.

Constant Summary collapse

ParseError =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Exception raised when JSON parsing fails

::Yajl::ParseError

Constants included from Options

Options::EMPTY_OPTIONS

Instance Method Summary collapse

Methods inherited from MultiJSON::Adapter

default_dump_options, default_generate_options, default_load_options, default_parse_options, defaults, dump, load

Methods included from Options

#default_dump_options, #default_generate_options, #default_load_options, #default_parse_options, #dump_options, #dump_options=, #generate_options, #generate_options=, #load_options, #load_options=, #parse_options, #parse_options=

Instance Method Details

#dump(object, options = {}) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialize a Ruby object to JSON

Examples:

Serialize object to JSON

adapter.dump({key: "value"}) #=> '{"key":"value"}'

Parameters:

  • object (Object)

    object to serialize

  • options (Hash) (defaults to: {})

    serialization options

Returns:

  • (String)

    JSON string



35
36
37
# File 'lib/multi_json/adapters/yajl.rb', line 35

def dump(object, options = {})
  ::Yajl::Encoder.encode(object, options)
end

#load(string, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a JSON string into a Ruby object

Examples:

Parse JSON string

adapter.load('{"key":"value"}') #=> {"key" => "value"}

Parameters:

  • string (String)

    JSON string to parse

  • options (Hash) (defaults to: {})

    parsing options

Returns:

  • (Object)

    parsed Ruby object



22
23
24
# File 'lib/multi_json/adapters/yajl.rb', line 22

def load(string, options = {})
  ::Yajl::Parser.new(options).parse(string)
end