toJSON

fun toJSON(key: Any? = definedExternally): String(source)

Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization.

MDN Reference