What are the u's when I use json.loads?

ZenLikeThat picture ZenLikeThat · Feb 8, 2012 · Viewed 21.1k times · Source

I've been writing a Python script to parse JSON information from the Soundcloud API, and I was just wondering what the "u"'s are when I use json.loads( val ) and how to store the JSON information to an object without the u's?

i.e. why are there u's in this:

>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]

See the "Decoding JSON" section here to understand what I mean further:

http://docs.python.org/library/json.html

Answer

Francis Avila picture Francis Avila · Feb 8, 2012

Unicode strings. See the Python Tutorial.

In Python source code, Unicode literals are written as strings prefixed with the ‘u’ or ‘U’ character: u'abcdefghijk'.

Unicode Literals in Python Source Code