Module: JSONAPI::Parser::JSONParser

Defined in:
lib/easy/jsonapi/parser/json_parser.rb

Overview

A wrapper class for OJ parser

Class Method Summary collapse

Class Method Details

.dump(ruby_hash) ⇒ Object

Convert ruby hash into JSON

Parameters:

  • ruby_hash (Hash)

    THe hash to convert into JSON



23
24
25
# File 'lib/easy/jsonapi/parser/json_parser.rb', line 23

def self.dump(ruby_hash)
  Oj.dump(ruby_hash, mode: :compat)
end

.parse(document, symbol_keys: true) ⇒ Object

Parse JSON string into a ruby hash

Parameters:

  • document (String)

    The JSON string to parse

Raises:



14
15
16
17
18
19
# File 'lib/easy/jsonapi/parser/json_parser.rb', line 14

def self.parse(document, symbol_keys: true)
  Oj.load(document, symbol_keys: symbol_keys)
  
rescue Oj::ParseError => e
  raise JSONAPI::Exceptions::JSONParseError, e.message
end