Method: Chef::JSONCompat.from_json

Defined in:
lib/chef/json_compat.rb

.from_json(source, opts = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/json_compat.rb', line 36

def from_json(source, opts = {})
  obj = parse(source, opts)

  # JSON gem requires top level object to be a Hash or Array (otherwise
  # you get the "must contain two octets" error). Yajl doesn't impose the
  # same limitation. For compatibility, we re-impose this condition.
  unless obj.is_a?(Hash) || obj.is_a?(Array)
    raise Chef::Exceptions::JSON::ParseError, "Top level JSON object must be a Hash or Array. (actual: #{obj.class})"
  end

  obj
end