toJson

abstract fun toJson(data: Any, prettyPrint: Boolean = false): String

Serializes the given data object into a JSON string.

Return

A JSON string representation of the provided data object.

Parameters

data

The object to be serialized into JSON format.

prettyPrint

Specifies whether the JSON string should be formatted with indentation for readability. Defaults to false for compact JSON.