Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON document) to a Python object. *encoding* determines the encoding used to interpret any :class:`bytes` objects decoded by this instance (``'utf-8'`` by default). It has no effect when decoding :class:`unicode` obj
(s, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None,
use_decimal=False, allow_nan=False, array_hook=None, **kw)
| 459 | |
| 460 | |
| 461 | def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, |
| 462 | parse_int=None, parse_constant=None, object_pairs_hook=None, |
| 463 | use_decimal=False, allow_nan=False, array_hook=None, **kw): |
| 464 | """Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON |
| 465 | document) to a Python object. |
| 466 | |
| 467 | *encoding* determines the encoding used to interpret any |
| 468 | :class:`bytes` objects decoded by this instance (``'utf-8'`` by |
| 469 | default). It has no effect when decoding :class:`unicode` objects. |
| 470 | |
| 471 | *object_hook*, if specified, will be called with the result of every |
| 472 | JSON object decoded and its return value will be used in place of the |
| 473 | given :class:`dict`. This can be used to provide custom |
| 474 | deserializations (e.g. to support JSON-RPC class hinting). |
| 475 | |
| 476 | *object_pairs_hook* is an optional function that will be called with |
| 477 | the result of any object literal decode with an ordered list of pairs. |
| 478 | The return value of *object_pairs_hook* will be used instead of the |
| 479 | :class:`dict`. This feature can be used to implement custom decoders |
| 480 | that rely on the order that the key and value pairs are decoded (for |
| 481 | example, :func:`collections.OrderedDict` will remember the order of |
| 482 | insertion). If *object_hook* is also defined, the *object_pairs_hook* |
| 483 | takes priority. |
| 484 | |
| 485 | *parse_float*, if specified, will be called with the string of every |
| 486 | JSON float to be decoded. By default, this is equivalent to |
| 487 | ``float(num_str)``. This can be used to use another datatype or parser |
| 488 | for JSON floats (e.g. :class:`decimal.Decimal`). |
| 489 | |
| 490 | *parse_int*, if specified, will be called with the string of every |
| 491 | JSON int to be decoded. By default, this is equivalent to |
| 492 | ``int(num_str)``. This can be used to use another datatype or parser |
| 493 | for JSON integers (e.g. :class:`float`). |
| 494 | |
| 495 | *allow_nan*, if True (default false), will allow the parser to |
| 496 | accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity`` |
| 497 | and enable the use of the deprecated *parse_constant*. |
| 498 | |
| 499 | If *use_decimal* is true (default: ``False``) then it implies |
| 500 | parse_float=decimal.Decimal for parity with ``dump``. |
| 501 | |
| 502 | *parse_constant*, if specified, will be |
| 503 | called with one of the following strings: ``'-Infinity'``, |
| 504 | ``'Infinity'``, ``'NaN'``. It is not recommended to use this feature, |
| 505 | as it is rare to parse non-compliant JSON containing these values. |
| 506 | |
| 507 | To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` |
| 508 | kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead |
| 509 | of subclassing whenever possible. |
| 510 | |
| 511 | """ |
| 512 | if (cls is None and encoding is None and object_hook is None and |
| 513 | parse_int is None and parse_float is None and |
| 514 | parse_constant is None and object_pairs_hook is None |
| 515 | and array_hook is None |
| 516 | and not use_decimal and not allow_nan and not kw): |
| 517 | return _default_decoder.decode(s) |
| 518 | if cls is None: |
searching dependent graphs…