Petri Lehtinen added the comment: It seems to me that when ensure_ascii is False, the return value will be a unicode instance if and only if there's a unicode object anywhere in the input.
json.dumps({'foo': 'bar'}, ensure_ascii=False) '{"foo": "bar"}'
json.dumps({'foo': u'bar'}, ensure_ascii=False) u'{"foo": "bar"}'
json.dumps({'foo': u'äiti'}, ensure_ascii=False) u'{"foo": "\xe4iti"}'
json.dumps({'foo': u'äiti'.encode('utf-8')}, ensure_ascii=False) '{"foo": "\xc3\xa4iti"}'
json.dumps({'foo': u'äiti'.encode('utf-16')}, ensure_ascii=False) '{"foo": "\xff\xfe\xe4\\u0000i\\u0000t\\u0000i\\u0000"}'
---------- nosy: +petri.lehtinen _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13769> _______________________________________