Function: json.encode_to_string

Encodes given object to a JSON string.

Identical to json.encode, except that the output is a string rather than bytes.

Usually, json.encode should be preferred to this function. Use this function only if you need to process the output as text. If you intend to send the resulting text payload over the network, always use UTF-8 charset, per https://tools.ietf.org/html/rfc8259#section-8.1.

Arguments

Arguments
data The input to be encoded.
indent Optional indentation options.

Returns

The encoded JSON string.

Raised exceptions

Exceptions
ValueError If the input contains types that cannot be JSON-encoded. Examples of such types include callable and bytes.