No, I was talking about output ports. The proposed procedure allows

1) writing JSON values larger than memory

2) pretty-printing (adding extra whitespace yourself)

3) printing valid elements of a JSON sequence as mentioned in the other issue)

3) perhaps most important, constructing different parts of the JSON by independent parts of the program, just as plain output ports allow constructing different parts of a text document.

It maintains a stack that is pushed whenever an object or array is opened.  Whenever an array or object is closed, pop the stack and validate that the close matches the current open.

A bad point is that allows printing incomplete JSON, but this trades off against all the other points.  The main JSON writer should be sure to validate everything before printing anything.

On Tue, Jan 21, 2020 at 8:31 AM Duy Nguyen <> wrote:
On Tue, Jan 21, 2020 at 8:00 PM Duy Nguyen <> wrote:
> On Tue, Jan 21, 2020 at 5:38 PM Amirouche Boubekki
> <> wrote:
> >
> > Le sam. 18 janv. 2020 à 22:52, John Cowan <> a écrit :
> > >
> > > I propose that json-stream-writer be added.  This accepts a port/accumulator and returns a procedure.  The contract for this procedure is the same as the procedure passed to json-stream-reader.  Any attempt to violate JSON rules of construction will signal an error satisfied by json-error?.
> >
> > Oh, that will allow to write a possibly bigger than memory JSON text?
> For me, that would allow me to customize the output (I hope) to print
> json with indentation.

Argh.. never mind. John was talking about input stream, not output.