BUG #14178: output of jsonb_object and json_object doesn't match textually

From: ap(at)zip(dot)com(dot)au
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14178: output of jsonb_object and json_object doesn't match textually
Date: 2016-06-07 01:42:34
Message-ID: 20160607014234.1381.95994@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14178
Logged by: Andrew P
Email address: ap(at)zip(dot)com(dot)au
PostgreSQL version: 9.5.1
Operating system: Linux, Debian, Jessie
Description:

Hi,

When presenting JSON output as TEXT, json_object seems to be the odd muppet
out:

field=# select json_object(ARRAY['moo', 'woof'], ARRAY['cow',
'dog'])::text;
json_object
---------------------------------
{"moo" : "cow", "woof" : "dog"}
(1 row)

Time: 0.428 ms
field=# select jsonb_object(ARRAY['moo', 'woof'], ARRAY['cow',
'dog'])::text;
jsonb_object
-------------------------------
{"moo": "cow", "woof": "dog"}
(1 row)

Time: 0.306 ms

I tried a few functions and all appear to be leaving no space before the
colon. Even to_json:

field=# select to_json('{"moo": "cow"}'::jsonb);
to_json
----------------
{"moo": "cow"}
(1 row)

Time: 0.400 ms

And cast:

field=# select cast('{"moo": "cow"}'::jsonb as json);
json
----------------
{"moo": "cow"}
(1 row)

Time: 0.398 ms

I think json_object should provide similar output. Consistency is nice
aesthetically and as being in line with the principle of least surprise.
Its lack may lead to possible unpleasant results if anyone tries to deal
with a JSON structure as TEXT (for whatever reason).

Andrew

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2016-06-07 02:40:27 Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
Previous Message Josh berkus 2016-06-06 20:23:30 Re: [BUGS] Routine analyze of single column prevents standard autoanalyze from running at all