Class: ChainReactor::Parsers::JsonParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/chain-reactor/parsers/json_parser.rb

Overview

Parse the string as a JSON object.

Instance Method Summary collapse

Methods inherited from Parser

#initialize, #parse

Constructor Details

This class inherits a constructor from ChainReactor::Parsers::Parser

Instance Method Details

#do_parse(string) ⇒ Object

Parse a JSON string, returning the result as a hash.

Raises a ParseError on failure.



10
11
12
13
14
15
16
17
# File 'lib/chain-reactor/parsers/json_parser.rb', line 10

def do_parse(string)
  begin
    @log.debug { "Parsing JSON string #{string.inspect}" }
    JSON.parse(string)
  rescue JSON::ParserError => e
    raise ParseError, "Data from client is not a valid JSON: #{string}, error: #{e.message}, data: #{string}"
  end
end