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

From: AP <ap(at)zip(dot)com(dot)au>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
Date: 2016-06-10 11:06:33
Message-ID: 20160610110633.GG18838@zip.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Jun 08, 2016 at 08:32:41PM +1000, AP wrote:
> > So after thinking more on the matter, I'd rather give up on such
> > patches and recommend doing ::jsonb::text to be able to do equality
> > comparisons. If you want to get output similar to what jsonb is doing,
> > a simple cast with ::jsonb looks rather the saner way to go. This
> > induces more parsing cost, but that's the cost to pay...
>
> I think two things are being somewhat conflated:
>
> 1. the look of our JSON structures - we should be consistent here
> 2. the ordering of our JSON structures internally - a related (for the above
> use case issue) but, ultimately, seperate issue.
>
> 1 is easy to solve. JSON is JSON is JSON whether it's in a JSON data-type or
> JSONB and so no matter which it should look the same.
(docs snipped)
> As you can see, the key ordering is already covered. If you care, stick to JSON.
> If you don't, fly JSONB airlines.
>
> I think it's still worth doing #1 above and I'm willing to do the patch
> myself (it didn't occur to me how simple it was and I've been kicking myself
> at losing the opportunity to contribute :( :) ) if need be and if it'll fly.

Well I got bored and did it anyway. I checked all the functions in the doc page
and modified accordingly. My patch is, obviously, a superset of Michael's. :)

Interesting tidbit wrt this bit in the docs for JSON:

"Because the json type stores an exact copy of the input text, it will
preserve semantically-insignificant white space between tokens, as well
as the order of keys within JSON objects."
- https://www.postgresql.org/docs/current/static/datatype-json.html

json_strip_nulls doesn't appear to adhere to that:

moo=# select json_strip_nulls('{ "a":"b", "c":["a",2,-5,null], "d":{"e":"f", "true": false, "false": true, "val": null}}');
json_strip_nulls
-----------------------------------------------------------------------
{"a":"b","c":["a",2,-5,null],"d":{"e":"f","true":false,"false":true}}
(1 row)

Not sure if this should be fixed in-code or a note be made in the docs
of the exceptions.

Anyhow, patch attached.

Andrew

Attachment Content-Type Size
json-formatting.patch text/x-diff 31.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message dmigowski 2016-06-11 09:41:03 BUG #14183: pgAdminIII doesn't display NEGATOR entries
Previous Message Francisco Olarte 2016-06-09 18:49:45 Re: Case in Order By Ignored without warning or error