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
JsonWriterwith the default pretty printing options. May be either aPrettyPrintOptionsinstance, or justtrueto enable pretty printing with defaults. Ifnullthen it defaults to the class default.writer := JsonWriter() writer := JsonWriter(true) writer := JsonWriter(PrettyPrintOptions { it.indent = "\t" })- prettyPrintOptions
const PrettyPrintOptions? prettyPrintOptions := nullDefault options used for pretty printing.
Is
nullif the default is NOT to pretty print.- writeJson
Str writeJson(Obj? obj, Obj? prettyPrintOptions := null)Convenience for serialising the given Fantom object to JSON.
prettyPrintOptionsmay be either aPrettyPrintOptionsinstance, or justtrueto enable pretty printing with defaults. Ifnullthen 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:
nullBoolNumStrStr:Obj?Obj?[]
prettyPrintOptionsmay be either aPrettyPrintOptionsinstance, or justtrueto 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" })