Function: json.encode

Encodes given input object to JSON bytes, using UTF-8 charset.

If indent is provided, it must be either a boolean, or a dictionary with two optional string attributes: prefix (defaulting to an empty string), and indent (defaulting to four spaces). Setting indent to true is equivalent to setting it to an empty dictionary. Setting indent to false is equivalent to not setting it.

When the indentation is enabled, each JSON element begins on a new line beginning with prefix and followed by zero or more copies of indent according to the structural nesting.


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


The resulting JSON bytes.

Raised exceptions

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