klyn.io.json.JSON.stringify
method
public static stringify(target as Object, object as Object = null, spaces as Boolean = true, pretty as Boolean = false, indent as Int = 0) as String throws IOException:
Description

Serializes a value as JSON.

  • JSON.stringify(value)
  • JSON.stringify(value, spaces=false)
  • JSON.stringify(value, pretty=true)
  • JSON.stringify(value, pretty=true, indent=2)
  • JSON.stringify(writerOrPathOrFile, value)
Parameters
ParameterDescription
targetValue to serialize, or an output sink (TextWriter, String, Path) when object is provided.
objectOptional value written to target when target is used as a sink.
spacesWhen pretty is false, controls compact spacing.
prettyEnables multi-line formatting.
indentIndentation width when pretty is true. A non-positive value falls back to 4 spaces.
Throws
  • IOException if the resource is closed, inaccessible, not a valid file, or the underlying I/O operation fails.
Example
config = {"fullscreen": true, "theme": "dark"}
print(JSON.stringify(config, pretty=true, indent=2))