2021-01-24 22:49:28 -05:00
|
|
|
:mod:`json` -- JSON encoding and decoding
|
2021-08-12 13:59:29 +10:00
|
|
|
=========================================
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2021-01-24 22:49:28 -05:00
|
|
|
.. module:: json
|
2014-10-31 01:37:19 +00:00
|
|
|
:synopsis: JSON encoding and decoding
|
|
|
|
|
2017-07-02 15:37:31 +03:00
|
|
|
|see_cpython_module| :mod:`python:json`.
|
|
|
|
|
2014-10-31 01:37:19 +00:00
|
|
|
This modules allows to convert between Python objects and the JSON
|
|
|
|
data format.
|
|
|
|
|
|
|
|
Functions
|
|
|
|
---------
|
|
|
|
|
2021-02-03 09:24:25 +01:00
|
|
|
.. function:: dump(obj, stream, separators=None)
|
2018-02-06 15:48:24 +11:00
|
|
|
|
2018-07-23 21:34:25 -04:00
|
|
|
Serialise ``obj`` to a JSON string, writing it to the given *stream*.
|
2018-02-06 15:48:24 +11:00
|
|
|
|
2021-02-03 09:24:25 +01:00
|
|
|
If specified, separators should be an ``(item_separator, key_separator)``
|
|
|
|
tuple. The default is ``(', ', ': ')``. To get the most compact JSON
|
|
|
|
representation, you should specify ``(',', ':')`` to eliminate whitespace.
|
|
|
|
|
|
|
|
.. function:: dumps(obj, separators=None)
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2018-07-23 21:34:25 -04:00
|
|
|
Return ``obj`` represented as a JSON string.
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2021-02-03 09:24:25 +01:00
|
|
|
The arguments have the same meaning as in `dump`.
|
|
|
|
|
2018-02-06 15:48:24 +11:00
|
|
|
.. function:: load(stream)
|
|
|
|
|
2018-07-23 21:34:25 -04:00
|
|
|
Parse the given ``stream``, interpreting it as a JSON string and
|
2018-02-06 15:48:24 +11:00
|
|
|
deserialising the data to a Python object. The resulting object is
|
|
|
|
returned.
|
|
|
|
|
|
|
|
Parsing continues until end-of-file is encountered.
|
2018-07-23 21:34:25 -04:00
|
|
|
A :exc:`ValueError` is raised if the data in ``stream`` is not correctly formed.
|
2014-10-31 01:37:19 +00:00
|
|
|
|
|
|
|
.. function:: loads(str)
|
|
|
|
|
2018-02-15 11:31:34 +11:00
|
|
|
Parse the JSON *str* and return an object. Raises :exc:`ValueError` if the
|
2014-10-31 01:37:19 +00:00
|
|
|
string is not correctly formed.
|