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

Source

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

Source

new make(Obj? options := null)

Creates a JsonWriter with the default pretty printing options.

options may be a map of values or just true to enable pretty printing with defaults. If null then the default is to NOT pretty print.

writer := JsonWriter()
writer := JsonWriter(true)
writer := JsonWriter(["prettyPrint":true, "indent":"  "])
options

Source

const Str:Obj? options

Options used for writing.

Defaults to:

["prettyPrint":false, "indent":"\t", "maxWidth":80]
writeJson

Source

Str writeJson(Obj? obj, Obj? options := null)

Convenience for serialising the given Fantom object to JSON.

options may be a map of values or just true to enable pretty printing with defaults. If null then it defaults to the class default.

json := jsonWriter.writeJson(jsonObj)
json := jsonWriter.writeJson(jsonObj, true)
json := jsonWriter.writeJson(jsonObj, ["prettyPrint":true, "indent":"  "])
writeJsonToStream

Source

This 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?[]

options may be a map of values or just true to enable pretty printing with defaults.

jsonWriter.writeJsonToStream(jsonObj, out)
jsonWriter.writeJsonToStream(jsonObj, out, true)
jsonWriter.writeJsonToStream(jsonObj, out, ["prettyPrint":true, "indent":"  "])