From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: JSON / ASP.NET AJAX Dates support in PostgreSQL
Date: Sat, 15 Apr 2023 12:46:59 +0200
Message-ID: <20230415104659.7vey676djxt36snz@hjp.at> (raw)
In-Reply-To: <910fb9a0-9744-0eed-58d4-648806cea02d@aklaver.com>
References: <DBAP191MB12896A817739B869A781C00CB0989@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
<c6fceaf9-0823-b2ad-ae00-3aa54ee017b1@gmail.com>
<20230414163116.ubjrzvgjtqafajcl@hjp.at>
<910fb9a0-9744-0eed-58d4-648806cea02d@aklaver.com>
On 2023-04-14 10:44:08 -0700, Adrian Klaver wrote:
> On 4/14/23 9:31 AM, Peter J. Holzer wrote:
> > On 2023-04-13 10:07:09 -0500, Ron wrote:
> > > On 4/13/23 09:44, Sebastien Flaesch wrote:
> > > Is there an easy way to convert JSON data containing ASP.NET AJAX Dates
> > > into PostgreSQL timestamp?
> > >
> > > I have this kind of JSON data:
> > >
> > > {
> > > "PurchaseOrder" : "4500000000",
> > > "CreationDate" : "\/Date(1672358400000)\/",
> > > "LastChangeDateTime" : "\/Date(1672692813062+0100)\/"
> > > }
> > >
> > > Warning: Note the backslash before the slashes!
> >
> > That's a Noop. According to RFC 8259, "\/" is the same as "/" (no idea
> > why they even specified that - it seems quite pointless).
>
> It is a cheat explained here:
>
> https://weblogs.asp.net/bleroy/dates-and-json
Yes, but it needs a specialized JSON parser to note that. As they write:
> Of course, a parser that doesn't know about this convention will just
> see a string,
And not only will it just see a string, it will output a string that's
indistinguishable from a string with the input
"/Date(1672692813062+0100)/". So any code after the parser can't detect
those extra backslashes. (This would include for example the object_hook
in the Python json Decoder which gets the decoded strings, not the raw
strings).
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: hjp-pgsql@hjp.at
Subject: Re: JSON / ASP.NET AJAX Dates support in PostgreSQL
In-Reply-To: <20230415104659.7vey676djxt36snz@hjp.at>
References: <DBAP191MB12896A817739B869A781C00CB0989@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> <c6fceaf9-0823-b2ad-ae00-3aa54ee017b1@gmail.com> <20230414163116.ubjrzvgjtqafajcl@hjp.at> <910fb9a0-9744-0eed-58d4-648806cea02d@aklaver.com> <20230415104659.7vey676djxt36snz@hjp.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox