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.
Examples
>>> to_json({"name": "test", "value": 42})
'{"name": "test", "value": 42}'See Also
- serialize(): Serialize to bytes using pickle (supports more types).
- from_json: Parse a JSON string back into a Python object.