The JSON_STREAM_OUTPUT
signature defines an interface for
stream-output of JSON values.
Synopsis
signature JSON_STREAM_OUTPUT
structure JSONBufferPrinter : JSON_STREAM_OUTPUT
where type outstream = CharBuffer.buf
structure JSONStreamPrinter : JSON_STREAM_OUTPUT
where type outstream = outstream
Interface
type outstream
type printer
val new : outstream -> printer
val new' : {strm : outstream, pretty : bool} -> printer
val close : printer -> unit
val null : printer -> unit
val boolean : printer * bool -> unit
val integer : printer * IntInf.int -> unit
val int : printer * int -> unit
val float : printer * real -> unit
val string : printer * string -> unit
val beginObject : printer -> unit
val objectKey : printer * string -> unit
val endObject : printer -> unit
val beginArray : printer -> unit
val endArray : printer -> unit
val value : printer * JSON.value -> unit
Description
type outstream
-
The type of the text consumer that the printer is layered on top of.
type printer
-
The
printer
type tracks the current state of the output so that it can correctly add punctuation and white space (when pretty printing). val new : outstream -> printer
-
new outS
creates a new printer from the output streamoutS
. The printer produces a condensed format without newlines or indentation; use thenew'
function to create a pretty-printer for JSON output. val new' : {strm : outstream, pretty : bool} -> printer
-
new' {strm, pretty}
creates a new pretty-printing stream from the output streamstrm
, where the value of thepretty
field controls whether the output is condensed (whenpretty
isfalse
) or printed with new lines and indentation to improve readability (whenpretty
istrue
). val close : printer -> unit
-
close pr
closes the printer, but not the underlying output stream. Closing the printer while there is an open object or array results in theFail
exception being raised. Also, calling any of the below printing functions on a closed printer will result in theFail
exception being raised. val null : printer -> unit
-
null pr
prints the JSON null value. Raises theFail
exception if the printer is closed. val boolean : printer * bool -> unit
-
boolean (pr, b)
prints the JSON boolean valueb
. Raises theFail
exception if the printer is closed. val integer : printer * IntInf.int -> unit
-
integer (pr, n)
prints the JSON numbern
. Raises theFail
exception if the printer is closed. val int : printer * int -> unit
-
int (pr, n)
prints the JSON numbern
. Raises theFail
exception if the printer is closed. This function is a convenience for when one wants to print a default-int-type value without converting it to aIntInf.int
first. val float : printer * real -> unit
-
float (pr, r)
prints the JSON floating-point numberr
. Raises theFail
exception if the printer is closed. val string : printer * string -> unit
-
string (pr, s)
prints the JSON strings
. Raises theFail
exception if the printer is closed. val beginObject : printer -> unit
-
beginArray pr
prints the opening “{” for a JSON object. Note that each call tobeginObject
should be matched by a call toendObject
. Raises theFail
exception if the printer is closed. val objectKey : printer * string -> unit
-
objectKey (pr, key)
prints the JSON key-valuekey
followed by a “:”. This function should be inside matchedbeginObject
/endObject
calls and should be followed by the printing of a JSON value. Raises theFail
exception if the printer is closed. val endObject : printer -> unit
-
endObject pr
prints the closing}
for the currently open object. TheFail
exception is raised if the current context is not an open object, if a key has been printed without an associated value, or if the printer is closed. val beginArray : printer -> unit
-
beginArray pr
prints the opening “[” for a JSON array. Note that each call tobeginArray
should be matched by a call toendArray
. Raises theFail
exception if the printer is closed. val endArray : printer -> unit
-
endArray pr
prints the closing]
for the currently open array. TheFail
exception is raised if the current context is not an open array or if the printer is closed. val value : printer * JSON.value -> unit
-
value (pr, v)
embeds the JSON valuev
in the output. It is equivalent to recursively traversing the JSON value while calling the appropriate output functions from above.