Re: making the backend's json parser work in frontend code - Mailing list pgsql-hackers

From David Steele
Subject Re: making the backend's json parser work in frontend code
Date
Msg-id f7a23062-18d6-8aa3-e168-23f5bc38652a@pgmasters.net
Whole thread Raw
In response to Re: making the backend's json parser work in frontend code  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: making the backend's json parser work in frontend code
List pgsql-hackers
Hi Robert,

On 1/16/20 11:51 AM, Robert Haas wrote:
> On Thu, Jan 16, 2020 at 1:37 PM David Steele <david@pgmasters.net> wrote:
> 
>> The next question in my mind is given the caveat that the error handing
>> is questionable in the front end, can we at least render/parse valid
>> JSON with the code?
> 
> That's a real good question. Thanks for offering to test it; I think
> that would be very helpful.

It seems to work just fine.  I didn't stress it too hard but I did put 
in one escape and a multi-byte character and check the various data types.

Attached is a test hack on pg_basebackup which produces this output:

START
     FIELD "number", null 0
     SCALAR TYPE 2: 123
     FIELD "string", null 0
     SCALAR TYPE 1: val    ue-丏
     FIELD "bool", null 0
     SCALAR TYPE 9: true
     FIELD "null", null 1
     SCALAR TYPE 11: null
END

I used the callbacks because that's the first method I found but it 
seems like json_lex() might be easier to use in practice.

I think it's an issue that the entire string must be passed to the lexer 
at once.  That will not be great for large manifests.  However, I don't 
think it will be all that hard to implement an optional "want more" 
callback in the lexer so JSON data can be fed in from the file in chunks.

So, that just leaves ereport() as the largest remaining issue?  I'll 
look at that today and Tuesday and see what I can work up.

Regards,
-- 
-David
david@pgmasters.net

Attachment

pgsql-hackers by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Binary support for pgoutput plugin
Next
From: David Steele
Date:
Subject: Re: making the backend's json parser work in frontend code