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.loads() on str erroneously returns str
Type: behavior Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: json.loads() on str should return unicode, not str
View: 10038
Assigned To: Nosy List: barry, pitrou
Priority: critical Keywords:

Created on 2010-10-27 20:41 by barry, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg119732 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-10-27 20:41
json is defined as mapping the JSON string type into unicodes.  This works as advertised in Python 2.6 and 3, but in Python 2.7 it returns a str.

% python2.6 -c "import json; print json.loads('{\"foo\":\"bar\"}')"
{u'foo': u'bar'}
% python2.7 -c "import json; print json.loads('{\"foo\":\"bar\"}')"
{'foo': 'bar'}

Platform tested so far: Ubuntu 10.10 amd64.
msg119733 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-10-27 20:42
BTW, the workaround for Python 2.7 is to pass a unicode to json.loads().
msg119735 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-10-27 20:43
Duplicate of issue10038.
msg119738 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-10-27 20:49
Yay.  I guess I have to submit a tracker bug now because searching for "json unicode" didn't turn up the original bug. ;/

Thanks for duping it __ap__.
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54425
2010-10-27 20:49:53barrysetmessages: + msg119738
2010-10-27 20:43:55pitrousetstatus: open -> closed

nosy: + pitrou
messages: + msg119735

superseder: json.loads() on str should return unicode, not str
resolution: duplicate
2010-10-27 20:42:17barrysetmessages: + msg119733
2010-10-27 20:41:16barrycreate