2021-08-12 04:59:29 +01:00
|
|
|
:mod:`json` -- JSON encoding and decoding
|
|
|
|
=========================================
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2021-08-12 04:59:29 +01:00
|
|
|
.. module:: json
|
2014-10-31 01:37:19 +00:00
|
|
|
:synopsis: JSON encoding and decoding
|
|
|
|
|
2017-07-02 13:37:31 +01: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 08:24:25 +00:00
|
|
|
.. function:: dump(obj, stream, separators=None)
|
2018-02-06 04:48:24 +00:00
|
|
|
|
|
|
|
Serialise *obj* to a JSON string, writing it to the given *stream*.
|
|
|
|
|
2021-02-03 08:24:25 +00: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-02-15 00:31:34 +00:00
|
|
|
Return *obj* represented as a JSON string.
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2021-02-03 08:24:25 +00:00
|
|
|
The arguments have the same meaning as in `dump`.
|
|
|
|
|
2018-02-06 04:48:24 +00:00
|
|
|
.. function:: load(stream)
|
|
|
|
|
|
|
|
Parse the given *stream*, interpreting it as a JSON string and
|
|
|
|
deserialising the data to a Python object. The resulting object is
|
|
|
|
returned.
|
|
|
|
|
|
|
|
Parsing continues until end-of-file is encountered.
|
|
|
|
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 00:31:34 +00: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.
|