toPrettyJson

Converts this object to a pretty-printed JSON string representation.

Uses the pre-configured JsonSerializer with default pretty printer for formatted output.

Receiver

The object to serialize. Can be any type.

Return

The pretty-printed JSON string representation of the object.

Throws

JsonProcessingException

if serialization fails.

Example:

val user = mapOf("name" to "John", "age" to 30)
val json = user.toPrettyJson()
// {
// "name" : "John",
// "age" : 30
// }