Unescaping Characters in a JSON response string

Spike picture Spike · Apr 5, 2011 · Viewed 15.6k times · Source

I made a JSON request that gives me a string that uses Unicode character codes that looks like:

s = "\u003Cp\u003E"

And I want to convert it to:

s = "<p>"

What's the best way to do this in Python?

Note, this is the same question as this one, only in Python except Ruby. I am also using the Posterous API.

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Apr 5, 2011
>>> "\\u003Cp\\u003E".decode('unicode-escape')
u'<p>'