Module: Ohai::Mixin::JsonHelper

Defined in:
lib/ohai/mixin/json_helper.rb

Instance Method Summary collapse

Instance Method Details

#parse_json(response_body, return_on_parse_error = nil) ⇒ Hash

parse JSON data from a String to a Hash

Parameters:

  • response_body (String)

    json as string to parse

  • return_on_parse_error (Object) (defaults to: nil)

    value to return if parsing fails

Returns:

  • (Hash)


27
28
29
30
31
32
33
# File 'lib/ohai/mixin/json_helper.rb', line 27

def parse_json(response_body, return_on_parse_error = nil)
  data = String(response_body)
  parser = FFI_Yajl::Parser.new
  parser.parse(data)
rescue FFI_Yajl::ParseError
  return_on_parse_error
end