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 98 def self.parse_json(s) begin value = JSON.parse(s) rescue JSON::ParserError=>e raise Sequel.convert_exception_class(e, Sequel::InvalidValue) end case value when Array JSONArray.new(value) when Hash JSONHash.new(value) else raise Sequel::InvalidValue, "unhandled json value: #{value.inspect} (from #{s.inspect})" end end
Make the column type detection recognize the json type.
# File lib/sequel/extensions/pg_json.rb, line 126 def schema_column_type(db_type) case db_type when 'json' :json else super end end