jsonpython-2.7unicodeescapingposterous

Unescaping Characters in a JSON response string


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.


Solution

  • If the data came from JSON, the json module should already have decoded these escapes for you:

    >>> import json
    >>> json.loads('"\u003Cp\u003E"')
    u'<p>'