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.
Note Fantom entities MUST be converted to standard lists and maps BEFORE being written by JsonWriter.
- 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? options := null)- Creates a - JsonWriterwith the default pretty printing options.- optionsmay be a map of values or just- trueto enable pretty printing with defaults. If- nullthen the default is to NOT pretty print.- writer := JsonWriter() writer := JsonWriter(true) writer := JsonWriter(["prettyPrint":true, "indent":" "]) 
- options
- Options used for writing. - Defaults to: - [ "prettyPrint" : false, "indent" : "\t", "maxWidth" : 80, "escapeUnicode" : true, ]- If enabled (default) then - escapeUnicodewill escape all characters over 0x7F using- \uXXXXnotation.
- writeJson
- Str writeJson(Obj? obj, Obj? options := null)- Convenience for serialising the given Fantom object to JSON. - optionsmay be a map of values or just- trueto enable pretty printing with defaults. If- nullthen it defaults to the class default.- json := jsonWriter.writeJson(jsonObj) json := jsonWriter.writeJson(jsonObj, true) json := jsonWriter.writeJson(jsonObj, ["prettyPrint":true, "indent":" "]) 
- writeJsonToStream
- OutStream writeJsonToStream(Obj? obj, OutStream out, Obj? options := 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?[]
 - optionsmay be a map of values or just- trueto enable pretty printing with defaults.- jsonWriter.writeJsonToStream(jsonObj, out) jsonWriter.writeJsonToStream(jsonObj, out, true) jsonWriter.writeJsonToStream(jsonObj, out, ["prettyPrint":true, "indent":" "]) - The - OutStreamis NOT closed, but is returned.