json.dump(
obj,
fp,
skipkeys=False,
ensure_ascii=True,
check_circular=True,
allow_nan=True,
cls=None,
indent=None,
separators=None,
encoding="utf-8",
default=None,
sort_keys=False,
**kw)
Serialize
obj as a JSON formatted stream to
fp (a .write()-supporting
file-like object) using this
conversion table.
If
skipkeys is true (default: False), then dict keys that are not of a basic type (
str,
unicode,
int,
long,
float,
bool, None) will be skipped instead of raising a
TypeError.
If
ensure_ascii is true (the default), all non-ASCII characters in the output are escaped with \uXXXX sequences, and the result is a
str instance consisting of ASCII characters only. If
ensure_ascii is false, some chunks written to
fp may be
unicode instances. This usually happens because the input contains unicode strings or the
encoding parameter is used. Unless fp.write() explicitly understands
unicode (as in
codecs.getwriter()) this is likely to cause an error.
If
check_circular is false (default: True), then the circular reference check for container types will be skipped and a circular reference will result in an
OverflowError (or worse).
If
allow_nan is false (default: True), then it will be a
ValueError to serialize out of range
float values (nan, inf, -inf) in strict compliance of the JSON specification. If
allow_nan is true, their JavaScript equivalents (NaN, Infinity, -Infinity) will be used.
If
indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, or negative, will only insert newlines. None (the default) selects the most compact representation.
Note
Since the default item separator is ', ', the output might include trailing whitespace when
indent is specified. You can use separators=(',', ': ') to avoid this.
If specified,
separators should be an (item_separator, key_separator) tuple. By default, (', ', ': ') are used. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.
encoding is the character encoding for str instances, default is UTF-8.
If specified,
default should be a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a
TypeError. If not specified,
TypeError is raised.
If
sort_keys is true (default: False), then the output of dictionaries will be sorted by key.
To use a custom
JSONEncoder subclass (e.g. one that overrides the default() method to serialize additional types), specify it with the
cls kwarg; otherwise
JSONEncoder is used.