
If object_hook is alsoĭefined, the object_pairs_hook takes priority.Ĭhanged in version 3.1: Added support for object_pairs_hook. Thisįeature can be used to implement custom decoders. Object_pairs_hook will be used instead of the dict. JSON object decoded with an ordered list of pairs.

Object_pairs_hook, if specified will be called with the result of every This can be used to provide custom deserializations (e.g. Object decoded and its return value will be used in place of the givenĭict. Object_hook, if specified, will be called with the result of every JSON It also understands NaN, Infinity, and -Infinity as theirĬorresponding float values, which is outside the JSON spec. Performs the following translations in decoding by default: JSONDecoder ( *, object_hook = None, parse_float = None, parse_int = None, parse_constant = None, strict = True, object_pairs_hook = None ) ¶ If object_hook is also defined, the object_pairs_hook takes priority.Ĭhanged in version 3.9: The keyword argument encoding has been removed. This feature can be used to implement custom decoders. Return value of object_pairs_hook will be used instead of theĭict. Result of any object literal decoded with an ordered list of pairs. Object_pairs_hook is an optional function that will be called with the Object_hook will be used instead of the dict. Object_hook is an optional function that will be called with the result ofĪny object literal decoded (a dict). read()-supporting text file orīinary file containing a JSON document) to a Python object using load ( fp, *, cls = None, object_hook = None, parse_float = None, parse_int = None, parse_constant = None, object_pairs_hook = None, ** kw ) ¶ĭeserialize fp (a. That is, loads(dumps(x)) != x if x has non-string Into JSON and then back into a dictionary, the dictionary may not equal

As a result of this, if a dictionary is converted WhenĪ dictionary is converted into JSON, all the keys of the dictionary areĬoerced to strings. Keys in key/value pairs of JSON are always of the type str. That string is used to indent each level. Of 0, negative, or "" will only insert newlines. Object members will be pretty-printed with that indent level. If indent is a non-negative integer or string, then JSON array elements and If allow_nan is true, their JavaScript equivalents ( NaN, Inf, -inf) in strict compliance of the JSON specification. ValueError to serialize out of range float values ( nan, If allow_nan is false (default: True), then it will be a Will result in an RecursionError (or worse).

Reference check for container types will be skipped and a circular reference If check_circular is false (default: True), then the circular If ensure_ascii isįalse, these characters will be output as-is. Have all incoming non-ASCII characters escaped. If ensure_ascii is true (the default), the output is guaranteed to The json module always produces str objects, notīytes objects. None) will be skipped instead of raising a TypeError. If skipkeys is true (default: False), then dict keys that are not write()-supportingįile-like object) using this conversion table.

Serialize obj as a JSON formatted stream to fp (a. 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 ) ¶ Order is only lost if the underlying containers are unordered. This module’s encoders and decoders preserve input and output order byĭefault.
