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 nhatcher
Recipients ezio.melotti, nhatcher, vstinner
Date 2018-04-10.09:21:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1523352074.24.0.682650639539.issue33255@psf.upfronthosting.co.za>
In-reply-to
Content
Hey I'm new here, so please let me know what incorrect things I am doing!

I _think_ `json.dumps(o, ensure_ascii=False)` is doing the wrong thing when `o` has both unicode and str keys/values. For instance:

```
import json
o = {u"greeting": "hi", "currency": "€"}
json.dumps(o, ensure_ascii=False, encoding="utf8")
json.dumps(o, ensure_ascii=False)
```

The first `dumps` will work while the second will fail. the reason is:

https://github.com/python/cpython/blob/2.7/Lib/json/encoder.py#L198

This will decode any str if the encoding is not 'utf-8'. In the mixed case (unicode and str) this will blow. I workaround is to use any of the aliases for 'utf-8' like 'utf8' or 'u8'.

I would be crazy happy to provide a PR if this is really an issue.
Let me know if extra clarification is needed.
Nicolás
History
Date User Action Args
2018-04-10 09:21:14nhatchersetrecipients: + nhatcher, vstinner, ezio.melotti
2018-04-10 09:21:14nhatchersetmessageid: <1523352074.24.0.682650639539.issue33255@psf.upfronthosting.co.za>
2018-04-10 09:21:14nhatcherlinkissue33255 messages
2018-04-10 09:21:13nhatchercreate