From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [PATCH] Generalized JSON output functions |
Date: | 2015-05-20 15:46:15 |
Message-ID: | 555CAC47.3040607@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 05/20/2015 09:16 AM, Shulgin, Oleksandr wrote:
> Hi, Hackers!
>
> Attached is a patch against master to generalize the JSON-producing
> functions in utils/adt/json.c and to provide a set of callbacks which
> can be overridden the same way that is already provided for *parsing*
> JSON.
>
> The motivation behind this to be able to produce specially-crafted
> JSON in a logical replication output plugin, such that numeric (and
> bigint) values are quoted. This requirement, in turn, arises from the
> fact that JavaScript specification, which is quite natural to expect
> as a consumer for this JSON data, allows to silently drop significant
> digits when converting from string to number object.
>
> I believe this is a well-known problem and I'm aware of a number of
> tricks that might be used to avoid it, but none of them seems to be
> optimal from my standpoint.
>
> I can also imagine this can be used to convert date/time to string
> differently, or adding indentation depending on the depth in object
> hierarchy, etc.
I'm not necessarily opposed to this, but it sure seems like a lot of
changes, and moderately invasive ones, to support something that could
be done, at the cost of reparsing, with a simple loadable extension that
I could create in a few hours of programming. The parser API was created
precisely to make this sort of transformation close to trivial. Other
fairly obvious transformations include translating to XML or YAML, and a
less obvious one could be something very specialized, like translating
certain fields. Anyway, for this purpose I could imagine a function like:
json_format (
j json (or text),
indent_spaces smallint default 0,
space_after_colon boolean default false,
space_after_comma boolean default false,
quote_numerics boolean default false)
returns json
cheers
andrew
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2015-05-20 15:47:15 | Re: Run pgindent now? |
Previous Message | Bruno Harbulot | 2015-05-20 15:43:49 | Re: Problems with question marks in operators (JDBC, ECPG, ...) |