Load JSON in Python as header character set

Posted by mridang on Stack Overflow See other posts from Stack Overflow or by mridang
Published on 2010-05-03T08:14:37Z Indexed on 2010/05/03 8:38 UTC
Read the original article Hit count: 265

Hi everyone,

I've always found character sets and encodings complicated to understand and here I'm faced with another problem. My apologies for any inaccuracies. I'll do my best.

I'm requesting data from a server which returns JSON. In the HTTP headers it also returns the character set like so:

Content-Type: text/html; charset=UTF-8

I'm using the JSON library in Python to load the JSON using the json.loads method. When I pass it the returned JSON, it gives me a dictionary in Unicode. I've Googled around and I know that JSON should return Unicode as JavaScript strings are Unicode objects. How can I load the JSON as UTF-8? I would like to use the same encoding as specified in the response header.

I've read this post but it didn't help.

Thank you.

© Stack Overflow or respective owner

Related posts about python

Related posts about JSON