Re: JSON in 9.2 - Could we have just one to_json() function instead of two separate versions ? - Mailing list pgsql-hackers

From David Johnston
Subject Re: JSON in 9.2 - Could we have just one to_json() function instead of two separate versions ?
Date
Msg-id 9A450013-8006-4EB9-B34E-D62A301DD51B@yahoo.com
Whole thread Raw
In response to Re: JSON in 9.2 - Could we have just one to_json() function instead of two separate versions ?  (Hannu Krosing <hannu@2ndQuadrant.com>)
Responses Re: JSON in 9.2 - Could we have just one to_json() function instead of two separate versions ?
List pgsql-hackers
On May 1, 2012, at 20:41, Hannu Krosing <hannu@2ndQuadrant.com> wrote:
>
> Most people don't work in strongly-typed environment, and thus would
> work around such restriction if they need a simple JSON value at the
> other end of the interchange.
>
>
>> My personal take it is have it fail since any arbitrary decision to cast
>> to JSON Text is going to make someone unhappy and supposedly they can
>> modify their query so that the result generates whatever format they desire.
>
> Do you actually have such an experience or is it just a wild guess ?
>
>

So even given the semantic differences between an object and a scalar I am better understanding where interpreting JSON
asJSON Value makes sense.  However, if I convert a record or array to JSON I expect to get a JSON Text even if the
thereis only a single column or value in the input.   

I guess my take is that record -> JSON text while anything else is JSON value.  Whether it is worth maiming the special
casefor record is worthwhile I really do not know but the semantic difference does exist; and record output is a
significantaspect of PostgreSQL output. 

I get the ease-of-use aspect but also recognize that sometimes being slightly harder to use is worthwhile if you
eliminateambiguities or limit the possibility to make mistakes. 

FWIW my background on this topic is more theoretical than experiential though I am an web-application developer by
tradeand do use some JSON in that capacity. 

David J.

pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: proposal: additional error fields
Next
From: Tom Lane
Date:
Subject: Re: Have we out-grown Flex?