Module | Sequel::Postgres::JSONDatabaseMethods |
In: |
lib/sequel/extensions/pg_json.rb
|
Methods enabling Database object integration with the json type.
Parse the given string as json, returning either a JSONArray or JSONHash instance, and raising an error if the JSON parsing does not yield an array or hash.
# File lib/sequel/extensions/pg_json.rb, line 94 94: def self.parse_json(s) 95: begin 96: value = JSON.parse(s) 97: rescue JSON::ParserError=>e 98: raise Sequel.convert_exception_class(e, Sequel::InvalidValue) 99: end 100: 101: case value 102: when Array 103: JSONArray.new(value) 104: when Hash 105: JSONHash.new(value) 106: else 107: raise Sequel::InvalidValue, "unhandled json value: #{value.inspect} (from #{s.inspect})" 108: end 109: end