to_json()
Serialize a Python object to a JSON string.
Usage
to_json(obj)Converts the given object into a human-readable JSON string. Supports dicts, lists, strings, numbers, booleans, and None.
Parameters
obj: object-
The Python object to serialize. Must be JSON-serializable.
Returns
str-
A JSON-formatted string.
Raises
TypeError-
If the object is not JSON-serializable.
See Also
- serialize()
-
Serialize to bytes using pickle (supports more types).
-
Parse a JSON string back into a Python object.
Examples
>>> to_json({"name": "test", "value": 42})‘{“name”: “test”, “value”: 42}’