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.

Author Brian.Merrell
Recipients Brian.Merrell
Date 2011-03-13.23:17:19
SpamBayes Score 8.2822034e-08
Marked as misclassified No
Message-id <1300058240.59.0.513243746739.issue11489@psf.upfronthosting.co.za>
In-reply-to
Content
The following works on Win7x64 Python 2.6.5 and breaks on Ubuntu 10.04x64-2.6.5.  This raises three issues:

1)  Shouldn't anything generated by json.dumps be parsed by json.loads?
2)  It appears this is an invalid unicode character.  Shouldn't this be caught by decode("utf8")
3)  Why does Windows raise no issue with this and Linux does?

import json
unicode_bytes = '\xed\xa8\x80'
unicode_string = unicode_bytes.decode("utf8")
json_encoded = json.dumps("my_key":unicode_string)
json.loads(json_encoded)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.6/json/decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.6/json/decoder.py", line 336, in raw_decode
    obj, end = self._scanner.iterscan(s, **kw).next()
  File "/usr/lib/python2.6/json/scanner.py", line 55, in iterscan
    rval, next_pos = action(m, context)
  File "/usr/lib/python2.6/json/decoder.py", line 183, in JSONObject
    value, end = iterscan(s, idx=end, context=context).next()
  File "/usr/lib/python2.6/json/scanner.py", line 55, in iterscan
    rval, next_pos = action(m, context)
  File "/usr/lib/python2.6/json/decoder.py", line 155, in JSONString
    return scanstring(match.string, match.end(), encoding, strict)
ValueError: Invalid \uXXXX escape: line 1 column 14 (char 14)
History
Date User Action Args
2011-03-13 23:17:20Brian.Merrellsetrecipients: + Brian.Merrell
2011-03-13 23:17:20Brian.Merrellsetmessageid: <1300058240.59.0.513243746739.issue11489@psf.upfronthosting.co.za>
2011-03-13 23:17:19Brian.Merrelllinkissue11489 messages
2011-03-13 23:17:19Brian.Merrellcreate