0

forI get a Json string as a body of a http response.

req = Request(url)
response = urlopen(req)
string = response.read().decode('utf-8')
json_obj = json.loads(string)
print(json_obj)

Every string in the json_obj is prepended by a 'u'.I want to get rid of all these 'u'. i understand that in python strings are encoded as unicode and thats what this u is representing, but i dont want it to be shown in my response, explicitly. How do i suppress this annoying 'u'.

I dont want to iterate through every value and remove 'u', as i am interested in entire response body. I am doing this for data collection, store the body in a file, pass this file to someone else to do some data extraction/analysis.

konquestor
  • 1,308
  • 3
  • 15
  • 29
  • 1
    `u''` objects are *unicode strings*. This is **normal**, you don't need to 'remove' these. What you see is container contents represented with `repr()` calls to make their contents clear; **print** the individual values. – Martijn Pieters Aug 20 '14 at 22:33
  • i want to dump sections of the response for data collection purpose, i cannot iterate through individual values. is there a way to remove 'u' through entire json object, instead of doing so on individual values? – konquestor Aug 20 '14 at 22:51
  • Don't turn whole lists or dictionaries to strings or tolerate the contents being printed as representations then. – Martijn Pieters Aug 20 '14 at 22:53

0 Answers0