[Python-Dev] Bug in json (the format and the module)

Jeremy Dunck jdunck at gmail.com
Tue May 17 20:48:44 CEST 2011


On Tue, May 17, 2011 at 1:21 PM, Dirkjan Ochtman <dirkjan at ochtman.nl> wrote:
> On Tue, May 17, 2011 at 19:40, Jeremy Dunck <jdunck at gmail.com> wrote:
>> So, to start with, is there a maintainer for the json module, or how
>> should I go about discussing implementing this solution?
>
> Your subject states that there is an actual bug in the json module,
> but your message fails to mention any actual bug. Is this what you
> mean?
>
> Python 2.7.1 (r271:86832, Mar 28 2011, 09:54:04)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import json
>>>> print json.dumps(u'foo\u2028bar')
> "foo\u2028bar"

Actually, that would be fine, and Bob's right that this is a non-issue
with ensure_ascii=True (the default).  His change upstream seems good
for the ensure_ascii=False case.

To be complete, this is what I meant:

>>> s = '{"JSON":"ro
cks!"}' # this string has a literal U+2028 in it
>>> s
'{"JSON":"ro\xe2\x80\xa8cks!"}'

>>> import json
>>> json.dumps(s) # fine by default
'"{\\"JSON\\":\\"ro\\u2028cks!\\"}"'

>>> json.dumps(s, ensure_ascii=False) # not fine with ensure_ascii=False
'"{\\"JSON\\":\\"ro\xe2\x80\xa8cks!\\"}"'


More information about the Python-Dev mailing list