klyn.io.json.JSON.stringify
method
public static stringify(notnull writer as TextWriter, value as Object, spaces as Boolean = true, pretty as Boolean = false, indent as Int = 0) as String throws JSONWriteException, IOException
Description

Serializes a value and writes it to a text writer.

Parameters
ParameterDescription
writerDestination writer.
valueValue to serialize, including null.
spacesWhen pretty is false, controls compact spacing.
prettyEnables multi-line formatting.
indentIndentation width when pretty is true.
Returns

The same JSON text written to writer.

Throws
  • JSONWriteException if the value cannot be represented as JSON.
  • IOException if the writer cannot accept the output.
  • NullException if writer is null at runtime; statically null arguments are rejected with TypeError.
Example
try writer = FileWriter("settings.json"):
    JSON.stringify(writer, {"theme": "dark"})