json.dumps()
json.dumps() is a Python function in the JSON Module category. Serializes a Python object to a JSON formatted string. The syntax is json.dumps(obj, *, skipkeys=False, ensure_ascii=True, indent=None, separators=None, default=None, sort_keys=False). Parameters: obj — Python object. Returns: JSON string. A typical example: import json
json.dumps({"a": 1, "b": 2}) # '{"a": 1, "b": 2}'
json.dumps({"a": 1}, indent=2) # Pretty-printed. A close sibling is json.loads(), which deserializes a JSON string to a Python object. A close sibling is json.dump(), which serializes a Python object to a JSON formatted stream (file). A close sibling is json.load(), which deserializes a JSON formatted stream (file) to a Python object. A close sibling is json.JSONEncoder(), which extensible JSON encoder for custom serialization. More about this category: JSON encoding and decoding — dump, load, dumps, loads. For a broader walkthrough, read the JSON Module guide. Related JSON Module entries: json.loads(), json.dump(), json.load(), json.JSONEncoder(), json.JSONDecoder().