diff --git a/web/pgadmin/static/js/slickgrid/editors.js b/web/pgadmin/static/js/slickgrid/editors.js index 0fae86ca..79b630e8 100644 --- a/web/pgadmin/static/js/slickgrid/editors.js +++ b/web/pgadmin/static/js/slickgrid/editors.js @@ -107,11 +107,7 @@ grid.copied_rows[row][cell] = 1; } } else { - if(column_type === 'jsonb') { - item[args.column.field] = JSON.parse(state); - } else { - item[args.column.field] = state; - } + item[args.column.field] = state; } } @@ -368,10 +364,8 @@ this.loadValue = function(item) { var data = defaultValue = item[args.column.field]; - /* If jsonb or array */ - if (data && typeof data === 'object' && !Array.isArray(data)) { - data = JSON.stringify(data, null, 4); - } else if (Array.isArray(data)) { + /* If array */ + if (Array.isArray(data)) { var temp = []; $.each(data, function(i, val) { if (typeof val === 'object') { @@ -395,11 +389,7 @@ }; this.applyValue = function(item, state){ - if(args.column.column_type_internal === 'jsonb') { - setValue(args, item, state, 'jsonb'); - } else { - setValue(args, item, state, 'text'); - } + setValue(args, item, state, 'text'); }; this.isValueChanged = function() { @@ -411,7 +401,8 @@ }; this.validate = function() { - if(args.column.column_type_internal === 'jsonb') { + if(args.column.column_type_internal === 'jsonb' || + args.column.column_type_internal === 'json') { try { JSON.parse($input.val()); } catch(e) { diff --git a/web/pgadmin/utils/driver/psycopg2/typecast.py b/web/pgadmin/utils/driver/psycopg2/typecast.py index 1f462f08..fe0edccd 100644 --- a/web/pgadmin/utils/driver/psycopg2/typecast.py +++ b/web/pgadmin/utils/driver/psycopg2/typecast.py @@ -170,6 +170,7 @@ def register_global_typecasters(): # Treat JSON data as text because converting it to dict alters the data # which should not happen as per postgres docs psycopg2.extras.register_default_json(loads=lambda x: x) + psycopg2.extras.register_default_jsonb(loads=lambda x: x) # pysycopg2 adapt does not support dict by default. Need to register # Used http://initd.org/psycopg/docs/extras.html#json-adaptation