type

JsonWriter

@Js
class JsonWriter : Obj

Write Haystack data in JSON format.

constructors

make

Wrap output stream.

fields

methods

close

Close the underlying output stream

flush

Flush the underlying output stream and return this

valToStr

Get a value as a JSON string.

writeGrid

Write the grid and return this

writeVal

Write any haystack value

Slot Details

close

Bool close()

Close the underlying output stream

flush

This flush()

Flush the underlying output stream and return this

make

new make(OutStream out, Dict? opts := null)

Wrap output stream. By default, the writer encodes JSON in the Haystack 4 (Hayson) format. Use the v3 option to encode JSON in the Haystack 3 format.

The following opts are supported:

  • v3 (Marker): write JSON in the Haystack 3 format
JsonWriter(out).writeVal(Etc.makeDict(["ts": DateTime.now])).close

JsonWriter(out, Etc.makeDict(["v3":Marker.val])).writeGrid(grid).close

opts

Dict opts { private set }

valToStr

static Str valToStr(Obj? val)

Get a value as a JSON string.

writeGrid

virtual override This writeGrid(Grid grid)

Write the grid and return this

writeVal

This writeVal(Obj? val)

Write any haystack value