🔵 🔵 🔵


Primary

၊၊||၊|။

json.dump() ⚬|Documentation|1st|20260208195155-00-⌔

json — JSON encoder and decoder — Python 3.14.3 documentation#json.dump

json.dump(obj, fp, ﹡, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, ﹡﹡kw)

Serialize obj as a JSON formatted stream to fp (a .write() -supporting file-like object) using this Python-to-JSON conversion table.

Note: Unlike pickle and marshal, JSON is not a framed protocol, so trying to serialize multiple objects with repeated calls to dump() using the same fp will result in an invalid JSON file.

Parameters:
  • obj (object) – The Python object to be serialized.
  • fp (file-like object) – The file-like object obj will be serialized to. The json module always produces str objects, not bytes objects, therefore fp.write() must support str input.
  • skipkeys (bool) – If True, keys that are not of a basic type (str, int, float, bool, None) will be skipped instead of raising a TypeError. Default False.
  • ensure_ascii (bool) – If True (the default), the output is guaranteed to have all incoming non-ASCII and non-printable characters escaped. If False, all characters will be outputted as-is, except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters U+0000 through U+001F.
  • check_circular (bool) – If False, the circular reference check for container types is skipped and a circular reference will result in a RecursionError (or worse). Default True.
  • allow_nan (bool) – If False, serialization of out-of-range float values (nan, inf, -inf) will result in a ValueError, in strict compliance with the JSON specification. If True (the default), their JavaScript equivalents (NaN, Infinity, -Infinity) are used.
  • cls (a JSONEncoder subclass) – If set, a custom JSON encoder with the default() method overridden, for serializing into custom datatypes. If None (the default), JSONEncoder is used.
  • indent (int * | * str * | * None) – If a positive integer or string, JSON array elements and object members will be pretty-printed with that indent level. A positive integer indents that many spaces per level; a string (such as "\t") is used to indent each level. If zero, negative, or "" (the empty string), only newlines are inserted. If None (the default), no newlines are inserted.
  • separators (tuple * | * None) – A two-tuple: (item_separator, key_separator). If None (the default), separators defaults to (',', ':') if indent is None, and (',', ':') otherwise. For the most compact JSON, specify (',', ':') to eliminate whitespace.
  • default (callable | None) – A function that is called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError. If None (the default), TypeError is raised.
  • sort_keys (bool) – If True, dictionaries will be outputted sorted by key. Default False.

Changed in version 3.2: Allow strings for indent in addition to integers.

Changed in version 3.4: Use (',', ':') as default if indent is not None.

Changed in version 3.6: All optional parameters are now keyword-only.

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •