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 vstinner
Recipients Kristian.Benoit, vstinner
Date 2014-05-14.21:49:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1400104198.9.0.0755359538288.issue21509@psf.upfronthosting.co.za>
In-reply-to
Content
In Python 2, json.loads() accepts str and unicode types. You can support JSON starting with a UTF-8 BOM using the Python codec "utf-8-sig". Example:

>>> codecs.BOM_UTF8 + b'{\n}'
'\xef\xbb\xbf{\n}'
>>> json.loads(codecs.BOM_UTF8 + b'{\n}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
>>> json.loads((codecs.BOM_UTF8 + b'{\n}').decode('utf-8-sig'))
{}
History
Date User Action Args
2014-05-14 21:49:58vstinnersetrecipients: + vstinner, Kristian.Benoit
2014-05-14 21:49:58vstinnersetmessageid: <1400104198.9.0.0755359538288.issue21509@psf.upfronthosting.co.za>
2014-05-14 21:49:58vstinnerlinkissue21509 messages
2014-05-14 21:49:58vstinnercreate