Class: HTTP::MimeType::JSON

Inherits:
Adapter
  • Object
show all
Defined in:
lib/http/mime_type/json.rb

Overview

JSON encode/decode MIME type adapter

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object

Decodes JSON string into Ruby object

Examples:

adapter = HTTP::MimeType::JSON.new
adapter.decode('{"foo":"bar"}')

Parameters:

  • str (String)

    JSON string to decode

Returns:

  • (Object)


33
34
35
# File 'lib/http/mime_type/json.rb', line 33

def decode(str)
  ::JSON.parse str
end

#encode(obj) ⇒ String

Encodes object to JSON

Examples:

adapter = HTTP::MimeType::JSON.new
adapter.encode(foo: "bar")

Parameters:

  • obj (Object)

    object to encode

Returns:

  • (String)


20
21
22
# File 'lib/http/mime_type/json.rb', line 20

def encode(obj)
  obj.to_json
end