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 JSONParseException, 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

Parameter | Description
--- | ---
`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.

Throws

- JSONParseException if the object graph contains a cyclic reference and therefore cannot be represented as JSON.
- 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))