Sha256: cc75d1f60465cec99a1d2cc88f8bdfdf36aaa28fc24c95900e070e2690fcbb28

Contents?: true

Size: 756 Bytes

Versions: 5

Compression:

Stored size: 756 Bytes

Contents

# frozen_string_literal: true

require 'oj'
require 'easy/jsonapi/exceptions/json_parse_error'

module JSONAPI
  module Parser
    # A wrapper class for OJ parser
    module JSONParser

      # Parse JSON string into a ruby hash
      # @param document [String] The JSON string to parse
      # @raise [JSONAPI::Exceptions::JSONParseError]
      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

      # Convert ruby hash into JSON
      # @param ruby_hash [Hash] THe hash to convert into JSON
      def self.dump(ruby_hash)
        Oj.dump(ruby_hash, mode: :compat)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easy-jsonapi-1.0.11 lib/easy/jsonapi/parser/json_parser.rb
easy-jsonapi-1.0.10 lib/easy/jsonapi/parser/json_parser.rb
easy-jsonapi-1.0.9 lib/easy/jsonapi/parser/json_parser.rb
easy-jsonapi-1.0.8 lib/easy/jsonapi/parser/json_parser.rb
easy-jsonapi-1.0.7 lib/easy/jsonapi/parser/json_parser.rb