toJsonString

inline fun <T> T.toJsonString(prettyPrint: Boolean = true): String

Serializes this value to a JSON string.

Return

the JSON string representation

Parameters

prettyPrint

if true, formats the output with indentation; otherwise outputs compact JSON

Type Parameters

T

the type to serialize (must be @Serializable or a JsonElement)


Deprecated

Passing an argument to toJsonString on a String serializes it as a JSON string literal. Use reformatJson.

Replace with

reformatJson()

Parses this String as JSON and re-encodes it as a pretty-printed JSON string. Extension function on String.