Module: Basquiat::Json

Defined in:
lib/basquiat/support/json.rb

Overview

A simple MultiJson wrapper to protect against eventual API changes.

Class Method Summary collapse

Class Method Details

.decode(object) ⇒ Hash

De-serializes a JSON into a Hash

Parameters:

  • object (Object)

    object to be de-serialized

Returns:

  • (Hash)

    Hash representing the JSON. The keys are symbolized by default

See Also:

  • MultiJson.load


18
19
20
21
22
# File 'lib/basquiat/support/json.rb', line 18

def self.decode(object)
  MultiJson.load(object, symbolize_keys: true)
rescue MultiJson::ParseError
  {}
end

.encode(object) ⇒ String

Serializes an Object into a JSON

Parameters:

  • object (Object)

    object to be serialized

Returns:

  • (String)

    JSON representation of the object

See Also:

  • MultiJson.dump


10
11
12
# File 'lib/basquiat/support/json.rb', line 10

def self.encode(object)
  MultiJson.dump(object)
end