How to exclude the key 'u' from below,
{u'{"auth":{"user_id":"2"},"data":{"collection":"master-services"}}': [u'']}
I need to get my dictionary like below,
{"auth":{"user_id":"2"},"data":{"collection":"master-services"}}
How to exclude the key 'u' from below,
{u'{"auth":{"user_id":"2"},"data":{"collection":"master-services"}}': [u'']}
I need to get my dictionary like below,
{"auth":{"user_id":"2"},"data":{"collection":"master-services"}}
It looks like you have a dictionary where the key(s) is JSON data. Try parsing it with a JSON parser.
>>> json.loads(list(data)[0])
{'auth': {'user_id': '2'}, 'data': {'collection': 'master-services'}}
If you have many such keys, you can iterate over data
(or, data.keys()
), like this:
>>> new_data = [json.loads(d) for d in data]
This gives you a list of dictionaries.
u stands for Unicode Text. It is used for creating Unicode strings. It is not a character that's stored in the dictionary.
You just need the key of the dictionary entry. Because there is only one key, you can do this:
my_dict = {u'{"auth":{"user_id":"2"},"data":{"collection":"master-services"}}': [u'']}
my_key = next(iter(my_dict))
my_key
will hold the value {"auth":{"user_id":"2"},"data":{"collection":"master-services"}}