This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: json.load() error message changed in 3.4
Type: Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, barry, berker.peksag, ezio.melotti, pitrou, r.david.murray, rhettinger, serhiy.storchaka, tshepang
Priority: normal Keywords:

Created on 2014-01-31 10:08 by barry, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
foo.py barry, 2014-01-31 10:08
20453.expansive barry, 2014-01-31 16:14 review
Messages (11)
msg209755 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2014-01-31 10:08
Run the attached file under Python 3.3 and you get:

No JSON object could be decoded

Run the same file under Python 3.4 and you get:

Expecting value: line 1 column 1 (char 0)

So a couple of things:

Since the error message changed, it makes it difficult to test in doctest and other text-based matches.  I'm also not sure the new message is "better".  Objectively speaking, probably both error messages are useful (i.e. that no json object was found, and where the problem was found).  I think the second message by itself is pretty mysterious.

I want to make sure the change was deliberate.  I couldn't find anything in Misc/NEWS which might not be entirely unexpected since specific error messages aren't generally a part of the guaranteed API.  Perhaps at the least, if the change was deliberate, let's document it in Misc/NEWS.
msg209759 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-31 10:32
Yes, the change is deliberate (issue16009).
msg209761 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2014-01-31 10:43
What do you think of combining the error messages, e.g.

No JSON object could be decoded, expecting value: line 1 column 1 (char 0)

?
msg209793 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-31 15:07
It seems to me that it should indeed have been that way.  I thought the referenced issue was *adding* the location information to the existing error messages.
msg209801 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2014-01-31 16:14
So, here's a patch that should work.  One thing I'm not positive about is that this is a more expansive change then just merging the two messages in the one case in the original description.  But it probably makes sense to be consistent.  Or should we try for a narrower fix?
msg209804 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-31 16:23
If backward compatibility is the concern, I'd think you'd just want to restore that one message.
msg209807 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2014-01-31 17:02
On Jan 31, 2014, at 04:23 PM, R. David Murray wrote:

>If backward compatibility is the concern, I'd think you'd just want to
>restore that one message.

Yeah.  I think the tests are a little more difficult to adjust in that case,
and of course, if we do change that one message it *won't* be completely
backward compatible (because it will have the additional information).
It's not a critical issue for me, so let's see if anybody else chimes in.
msg209978 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-02 12:49
"No JSON object could be decoded, expecting value" is too expensive and second part of this message just repeat first part. The message can be shortened to "No JSON object could be decoded". But this is not fully correct. JSON term "object" corresponds to Python dict. But this error raised when arbitrary JSON value expected: "object", "array" (corresponded to Python list), string, number or boolean. That is why I had changed "object" to "value". So may be the "No JSON value could be decoded" is more correct.

Also note other differences between 3.3 and 3.4:

json.loads('[')
3.3: Expecting object: line 1 column 1 (char 0)
3.4: Expecting value: line 1 column 2 (char 1)

json.loads('[,')
3.3: No JSON object could be decoded
3.4: Expecting value: line 1 column 2 (char 1)

json.loads('[42')
3.3: Expecting object: line 1 column 3 (char 2)
3.4: Expecting ',' delimiter: line 1 column 4 (char 3)

json.loads('[42,')
3.3: Expecting object: line 1 column 4 (char 3)
3.4: Expecting value: line 1 column 5 (char 4)

json.loads('["')
3.3: end is out of bounds
3.4: Unterminated string starting at: line 1 column 2 (char 1)

json.loads('["foo')
3.3: Unterminated string starting at: line 1 column 2 (char 1)
3.4: Unterminated string starting at: line 1 column 2 (char 1)

To me new error messages look more informative and more correct.
msg209979 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-02 12:51
> To me new error messages look more informative and more correct.

Yes, I agree with you.
msg231993 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-02 13:03
In issue19361 I suggest to change error messages even more and drop end position from "Extra data" error message.
msg264409 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-04-28 04:36
3.4 is in security-fix-only mode and 3.5+ has better error messages thanks to JSONDecodeError (07af9847dbec). Closing this as 'out of date'.
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64652
2016-04-28 04:36:09berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg264409

resolution: out of date
stage: resolved
2014-12-02 17:04:42Arfreversetnosy: + Arfrever
2014-12-02 13:03:35serhiy.storchakasetmessages: + msg231993
2014-02-02 12:51:05pitrousetmessages: + msg209979
2014-02-02 12:49:36serhiy.storchakasetmessages: + msg209978
2014-01-31 21:01:24tshepangsetnosy: + tshepang
2014-01-31 17:02:00barrysetmessages: + msg209807
2014-01-31 16:23:04r.david.murraysetmessages: + msg209804
2014-01-31 16:14:19barrysetfiles: + 20453.expansive

messages: + msg209801
2014-01-31 15:07:54r.david.murraysetnosy: + r.david.murray
messages: + msg209793
2014-01-31 10:43:52barrysetmessages: + msg209761
2014-01-31 10:32:19serhiy.storchakasetnosy: + rhettinger, ezio.melotti, serhiy.storchaka, pitrou
messages: + msg209759
2014-01-31 10:08:51barrycreate