Re: JSON / ASP.NET AJAX Dates support in PostgreSQL

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: JSON / ASP.NET AJAX Dates support in PostgreSQL
Date: 2023-04-15 10:46:59
Message-ID: 20230415104659.7vey676djxt36snz@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-04-15 13:40:44 Re: Guidance on INSERT RETURNING order
Previous Message Alexander Farber 2023-04-15 10:06:21 Should I add a new schema for my application?