json.load()
¶
-
json.
load
(fp, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)[source]¶ Deserialize
fp
(a.read()
-supporting file-like object containing a JSON document) to a Python object.If the contents of
fp
is encoded with an ASCII based encoding other than utf-8 (e.g. latin-1), then an appropriateencoding
name must be specified. Encodings that are not ASCII based (such as UCS-2) are not allowed, and should be wrapped withcodecs.getreader(fp)(encoding)
, or simply decoded to aunicode
object and passed toloads()
object_hook
is an optional function that will be called with the result of any object literal decode (adict
). The return value ofobject_hook
will be used instead of thedict
. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting).object_pairs_hook
is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value ofobject_pairs_hook
will be used instead of thedict
. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.OrderedDict will remember the order of insertion). Ifobject_hook
is also defined, theobject_pairs_hook
takes priority.To use a custom
JSONDecoder
subclass, specify it with thecls
kwarg; otherwiseJSONDecoder
is used.