2021-08-11 23:59:29 -04:00
|
|
|
:mod:`json` -- JSON encoding and decoding
|
|
|
|
=========================================
|
2014-10-30 21:37:19 -04:00
|
|
|
|
2021-08-11 23:59:29 -04:00
|
|
|
.. module:: json
|
2014-10-30 21:37:19 -04:00
|
|
|
:synopsis: JSON encoding and decoding
|
|
|
|
|
2017-07-02 08:37:31 -04:00
|
|
|
|see_cpython_module| :mod:`python:json`.
|
|
|
|
|
2014-10-30 21:37:19 -04:00
|
|
|
This modules allows to convert between Python objects and the JSON
|
|
|
|
data format.
|
|
|
|
|
|
|
|
Functions
|
|
|
|
---------
|
|
|
|
|
2021-02-03 03:24:25 -05:00
|
|
|
.. function:: dump(obj, stream, separators=None)
|
2018-02-05 23:48:24 -05:00
|
|
|
|
|
|
|
Serialise *obj* to a JSON string, writing it to the given *stream*.
|
|
|
|
|
2021-02-03 03:24:25 -05: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-30 21:37:19 -04:00
|
|
|
|
2018-02-14 19:31:34 -05:00
|
|
|
Return *obj* represented as a JSON string.
|
2014-10-30 21:37:19 -04:00
|
|
|
|
2021-02-03 03:24:25 -05:00
|
|
|
The arguments have the same meaning as in `dump`.
|
|
|
|
|
2018-02-05 23:48:24 -05: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-30 21:37:19 -04:00
|
|
|
.. function:: loads(str)
|
|
|
|
|
2018-02-14 19:31:34 -05:00
|
|
|
Parse the JSON *str* and return an object. Raises :exc:`ValueError` if the
|
2014-10-30 21:37:19 -04:00
|
|
|
string is not correctly formed.
|