const classafJson::JsonWriter
sys::Obj afJson::JsonWriter
@
Js
(Service) - Writes Fantom objects to JSON, optionally performing pretty printing.
Pretty printing takes more processing than basic printing, but helps debugging.
- convertHook
virtual Obj? convertHook(Obj? val)
A simple override hook to alter values before they are written.
By default this just returns the given value.
- make
new make(Obj? prettyPrintOptions := null)
Creates a
JsonWriter
with the default pretty printing options. May be either aPrettyPrintOptions
instance, or justtrue
to enable pretty printing with defaults.If
null
then the default is to NOT pretty print.writer := JsonWriter() writer := JsonWriter(true) writer := JsonWriter(PrettyPrintOptions { it.indent = "\t" })
- prettyPrintOptions
const PrettyPrintOptions? prettyPrintOptions := null
Default options used for pretty printing.
If
null
then the default is to NOT pretty print.- writeJson
Str writeJson(Obj? obj, Obj? prettyPrintOptions := null)
Convenience for serialising the given Fantom object to JSON.
prettyPrintOptions
may be either aPrettyPrintOptions
instance, or justtrue
to enable pretty printing with defaults. Ifnull
then it defaults to the class default.json := jsonWriter.writeJson(jsonObj) json := jsonWriter.writeJson(jsonObj, true) json := jsonWriter.writeJson(jsonObj, PrettyPrintOptions { it.indent = "\t" })
- writeJsonToStream
This writeJsonToStream(Obj? obj, OutStream out, Obj? prettyPrintOptions := null)
Write the given object as JSON to this stream. The obj must be one of the following:
null
Bool
Num
Str
Str:Obj?
Obj?[]
prettyPrintOptions
may be either aPrettyPrintOptions
instance, or justtrue
to enable pretty printing with defaults.json := jsonWriter.writeJsonToStream(jsonObj, out) json := jsonWriter.writeJsonToStream(jsonObj, out, true) json := jsonWriter.writeJsonToStream(jsonObj, out, PrettyPrintOptions { it.indent = "\t" })