Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert this particular json string into a python dictionary?

Tags:

python

json

How do I convert this string ->

 string = [{"name":"sam"}]

into a python dictionary like so ->

data = {
         "name" : "sam"
       }
like image 718
Sai Krishna Avatar asked Dec 05 '22 20:12

Sai Krishna


1 Answers

In [1]: import json

In [2]: json.loads('[{"name":"sam"}]')
Out[2]: [{u'name': u'sam'}]

This returns a list, the first element of which is the desired dictionary.

like image 112
NPE Avatar answered Jan 04 '23 22:01

NPE