0

I am having issues removing unicode from a dictionary. I tried to use the encode method but the 'u' is still printing out. I am trying to put my data into a JSON editor, but it doesn't like unicode. Any help would be great!

original print statement:

print get_photo_data(photo_ids)

attempt to use encode method:

print get_photo_data(photo_ids.encode('utf-8'))

Some of JSON with unicode:

{u'photo': {u'people': {u'haspeople': 0}, u'dateuploaded': u'1492693219', u'owner': {u'username': u'jrobfoto.com', u'realname': u'Jonathan Robson', u'nsid': u'26449190@N00', u'iconserver': u'1360', u'location': u'Naperville, USA', u'path_alias': u'robsonj', u'iconfarm': 2}, u'publiceditability': {u'canaddmeta': 1, u'cancomment': 1}, u'id': u'34157653485', u'title': {u'_content': u'shared with pixbuf'}, u'media': u'photo', u'tags':
Avery9115
  • 135
  • 2
  • 13
  • 2
    That's a Python dictionary not a JSON string. You should use `json.dumps` to convert to JSON – Moses Koledoye Apr 20 '17 at 13:19
  • [Suppress the u'prefix indicating unicode' in python strings](http://stackoverflow.com/questions/761361/suppress-the-uprefix-indicating-unicode-in-python-strings) – Casper Apr 20 '17 at 13:19
  • Thats not `JSON` you have but a python dictionary. They have the similar structure but are not the same, you should use the `json` methods available in python https://docs.python.org/2/library/json.html – Craicerjack Apr 20 '17 at 13:21
  • Possible duplicate of [Python dictionary : removing u' chars](http://stackoverflow.com/questions/8101649/python-dictionary-removing-u-chars) – marmeladze Apr 20 '17 at 13:21
  • Awesome I used json.dumps to convert it into JSON. Thanks! – Avery9115 Apr 20 '17 at 13:30

1 Answers1

0

You can print it like this :-

import json
print(
    json.dumps(
        get_photo_data(photo_ids),
        sort_keys=True,
        indent=4,
        separators=(',', ': ')
    )
)

see here for more

toanant
  • 331
  • 3
  • 9