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)` `Path`) when `object` is provided. falls back to 4 spaces.
config = {"fullscreen": true, "theme": "dark"}
print(JSON.stringify(config, pretty=true, indent=2))
Parameters
  • target Value to serialize, or an output sink (`TextWriter`, `String`, `Path`) when `object` is provided.
  • object Optional value written to `target` when `target` is used as a sink.
  • spaces When `pretty` is false, controls compact spacing.
  • pretty Enables multi-line formatting.
  • indent Indentation width when `pretty` is true. A non-positive value falls back to 4 spaces. ```klyn config = {"fullscreen": true, "theme": "dark"} print(JSON.stringify(config, pretty=true, indent=2)) ```