Class: ReeJson::FromJson

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb

Constant Summary collapse

ParseJsonError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#call(object, **opts) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ree_lib/packages/ree_json/package/ree_json/functions/from_json.rb', line 15

def call(object, **opts)
  options = {}

  if opts.delete(:symbol_keys)
    options[:symbolize_names] = true
  end

  JSON.parse(object, **options)
rescue JSON::ParserError, ArgumentError, EncodingError, TypeError
  raise ParseJsonError.new
end