What are the u's when I use json.loads? [duplicate] What are the u's when I use json.loads? [duplicate] python python

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


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


the u's are there to indicate that a Unicode string is supposed to be created.

It sucks that json.dump converts strings to unicode strings and leaves no trace of having done that, because then json.load can't convert back.

To convert to string objects, use PyYAML:

>>> import yaml>>> yaml.load('["foo", {"bar":["baz", null, 1.0, 2]}]')>>> ['foo', {'bar': ['baz', None, 1.0, 2]}]

But careful! If for some reason you json.dumped an object containing object strings and unicode strings, yaml will load everything as object strings (though that's json.dump's fault really)