Issue19361
Created on 2013-10-23 11:22 by musically_ut, last changed 2015-01-26 11:17 by python-dev. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| json_JSONDecodeError.patch | serhiy.storchaka, 2014-10-05 10:16 | review | ||
| json_JSONDecodeError_2.patch | serhiy.storchaka, 2014-11-30 22:20 | review | ||
| Messages (9) | |||
|---|---|---|---|
| msg201015 - (view) | Author: Utkarsh Upadhyay (musically_ut) * | Date: 2013-10-23 11:22 | |
The JSON parser currently throws exceptions which contain information about where the error happened but this information is encoded in a string and not available to the programmer. This leads to issues like this: http://stackoverflow.com/questions/19519409/how-to-get-error-location-from-json-loads-in-python Would it be a problem if the errors thrown were specialized exceptions, e.g. JSONParsingError, which has ValueError as a base class with these details (line number, char number, etc.) exposed as public members? The changes required seem to be limited to changing http://hg.python.org/cpython/file/4c4f31a1b706/Lib/json/decoder.py and the related documentation. |
|||
| msg201025 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2013-10-23 13:56 | |
Simplejson already have JSONDecodeError.
class JSONDecodeError(ValueError):
"""Subclass of ValueError with the following additional properties:
msg: The unformatted error message
doc: The JSON document being parsed
pos: The start index of doc where parsing failed
end: The end index of doc where parsing failed (may be None)
lineno: The line corresponding to pos
colno: The column corresponding to pos
endlineno: The line corresponding to end (may be None)
endcolno: The column corresponding to end (may be None)
"""
Adding it to the stdlib is only matter of time.
|
|||
| msg201028 - (view) | Author: Utkarsh Upadhyay (musically_ut) * | Date: 2013-10-23 14:06 | |
Excellent! Is there an issue for merging Simplejson into stdlib? If so, can this issue be linked to that issue? |
|||
| msg218930 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2014-05-22 22:58 | |
> Adding it to the stdlib is only matter of time. I think we can go forward with it right now. |
|||
| msg218935 - (view) | Author: Bob Ippolito (bob.ippolito) * | Date: 2014-05-22 23:20 | |
simplejson v3.5.1 is probably a good target, let me know if there's anything that you'd like me to merge back in from stdlib to make maintenance easier. I haven't been tracking stdlib except when I've been added to issues. |
|||
| msg228555 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2014-10-05 10:15 | |
Here is a patch which adopts JSONDecodeError from simplejson. Unlike to simplejson it is located in the json.decoder module (json uses different way to pass an error from scanner to decoder). |
|||
| msg231501 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2014-11-21 21:17 | |
While we here may be change error messages? The only error which contains end position is "Extra data". And it doesn't look clean to me why end position should be mentioned at all (it is always len(data) here). I suggest to drop it, this will make error message cleaner and JSONDecodeError simpler. May be mention line and column in error message only if JSON data is multiline? Most machine generated data has one line only. Instead of "Expecting ',' delimiter: line 1 column 123 (char 124)" I suggest "Expecting ',' delimiter at position 124". Same as in re.error. |
|||
| msg231907 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2014-11-30 22:20 | |
Updated patch provides JSONDecodeError without end* attributes and with changed message for "Extra data". |
|||
| msg234734 - (view) | Author: Roundup Robot (python-dev) | Date: 2015-01-26 11:17 | |
New changeset 07af9847dbec by Serhiy Storchaka in branch 'default': Issue #19361: JSON decoder now raises JSONDecodeError instead of ValueError. https://hg.python.org/cpython/rev/07af9847dbec |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2015-01-26 11:17:42 | python-dev | set | nosy:
+ python-dev messages: + msg234734 |
| 2015-01-26 11:17:41 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2014-12-02 17:04:35 | Arfrever | set | nosy:
+ Arfrever |
| 2014-11-30 22:20:31 | serhiy.storchaka | set | files:
+ json_JSONDecodeError_2.patch messages: + msg231907 |
| 2014-11-21 21:17:59 | serhiy.storchaka | set | messages: + msg231501 |
| 2014-10-05 10:16:33 | serhiy.storchaka | set | files:
+ json_JSONDecodeError.patch keywords: + patch |
| 2014-10-05 10:15:47 | serhiy.storchaka | set | versions:
+ Python 3.5, - Python 3.4 messages: + msg228555 assignee: serhiy.storchaka |
| 2014-05-22 23:20:37 | bob.ippolito | set | messages: + msg218935 |
| 2014-05-22 22:58:39 | rhettinger | set | nosy:
+ bob.ippolito messages: + msg218930 |
| 2014-05-16 04:32:14 | cvrebert | set | nosy:
+ cvrebert |
| 2013-10-23 14:06:43 | musically_ut | set | messages: + msg201028 |
| 2013-10-23 13:56:31 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg201025 |
| 2013-10-23 11:25:09 | ezio.melotti | set | nosy:
+ rhettinger, pitrou, ezio.melotti components:
+ Library (Lib) |
| 2013-10-23 11:22:14 | musically_ut | create | |