diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 13:16:30 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 13:16:30 +0200 |
commit | bbbad609cb4e73b86a9beed203994ae55bce3867 (patch) | |
tree | d38fd6982ecc674808032dcfb851d1bb72e712a7 /Doc/library/json.rst | |
parent | c019871226f4c87c4439f1f0635dc9e83ac43a9f (diff) | |
download | cpython-bbbad609cb4e73b86a9beed203994ae55bce3867.tar.gz |
Issue #19361: JSON decoder now raises JSONDecodeError instead of ValueError.
Diffstat (limited to 'Doc/library/json.rst')
-rw-r--r-- | Doc/library/json.rst | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 0dad6ad9cc..49bb0905e0 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -250,7 +250,7 @@ Basic Usage will be passed to the constructor of the class. If the data being deserialized is not a valid JSON document, a - :exc:`ValueError` will be raised. + :exc:`JSONDecodeError` will be raised. .. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) @@ -261,7 +261,7 @@ Basic Usage *encoding* which is ignored and deprecated. If the data being deserialized is not a valid JSON document, a - :exc:`ValueError` will be raised. + :exc:`JSONDecodeError` will be raised. Encoders and Decoders --------------------- @@ -334,13 +334,16 @@ Encoders and Decoders ``'\n'``, ``'\r'`` and ``'\0'``. If the data being deserialized is not a valid JSON document, a - :exc:`ValueError` will be raised. + :exc:`JSONDecodeError` will be raised. .. method:: decode(s) Return the Python representation of *s* (a :class:`str` instance containing a JSON document) + :exc:`JSONDecodeError` will be raised if the given JSON document is not + valid. + .. method:: raw_decode(s) Decode a JSON document from *s* (a :class:`str` beginning with a @@ -469,6 +472,36 @@ Encoders and Decoders mysocket.write(chunk) +Exceptions +---------- + +.. exception:: JSONDecodeError(msg, doc, pos, end=None) + + Subclass of :exc:`ValueError` with the following additional attributes: + + .. attribute:: msg + + The unformatted error message. + + .. attribute:: doc + + The JSON document being parsed. + + .. attribute:: pos + + The start index of *doc* where parsing failed. + + .. attribute:: lineno + + The line corresponding to *pos*. + + .. attribute:: colno + + The column corresponding to *pos*. + + .. versionadded:: 3.5 + + Standard Compliance and Interoperability ---------------------------------------- |