diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 11:16:30 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 11:16:30 (GMT) |
commit | 47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81 (patch) | |
tree | b3e5115125360618a02a9615a643cbebe4aa7e75 /Doc/library/json.rst | |
parent | 4e5d9eac2ca03debecbb9c6ed873303d04ead06a (diff) | |
download | cpython-47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81.zip cpython-47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81.tar.gz cpython-47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81.tar.bz2 |
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 0dad6ad..49bb090 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 ---------------------------------------- |