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

From: David Johnston <polobo(at)yahoo(dot)com>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Joey Adams <joeyadams3(dot)14159(at)gmail(dot)com>, PavelStehule <pavel(dot)stehule(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: JSON in 9.2 - Could we have just one to_json() function instead of two separate versions ?
Date: 2012-05-02 01:22:55
Message-ID: 9A450013-8006-4EB9-B34E-D62A301DD51B@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On May 1, 2012, at 20:41, Hannu Krosing <hannu(at)2ndQuadrant(dot)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 as JSON Value makes sense. However, if I convert a record or array to JSON I expect to get a JSON Text even if the there is 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 case for record is worthwhile I really do not know but the semantic difference does exist; and record output is a significant aspect of PostgreSQL output.

I get the ease-of-use aspect but also recognize that sometimes being slightly harder to use is worthwhile if you eliminate ambiguities 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 trade and do use some JSON in that capacity.

David J.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-05-02 02:25:32 Re: Have we out-grown Flex?
Previous Message Peter Geoghegan 2012-05-02 01:01:48 Re: proposal: additional error fields