Python string to dictionary with json (not working)
<p>I have a text file like this :</p>

<p>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"</p>

<p>and i want to convert to dictionary this file. Because i want to take values. </p>

<pre><code>import json
from time import sleep

def buffer(data):
    dicto=json.loads(data) 
    print(type(dicto))      

file=open("config.txt", "r").read()
jsondata=json.dumps(file)  
buffer(jsondata)

result : &lt;class 'str'&gt;
</code></pre>

<p>When i working in shell like this :</p>

<pre><code>&gt;&gt;&gt; import json
&gt;&gt;&gt; h = '{"foo":"bar", "foo2":"bar2"}'
&gt;&gt;&gt; type(h)
&lt;class 'str'&gt;
&gt;&gt;&gt; d=json.loads(h)
&gt;&gt;&gt; d
{'foo2': 'bar2', 'foo': 'bar'}
&gt;&gt;&gt; type(d)
&lt;class 'dict'&gt;
&gt;&gt;&gt; 
</code></pre>

<p>its working but i can't understand why my code not working. When i convert this file to dictionary i want to hold in a buffer. How can i hold this data inside array? Please excuse me i am new in Python.</p>

<pre><code>import json
from time import sleep

def buffer(data):
    s = json.loads(data) 
    dicto = {}
    tmp_list = s.split(',')
    for e in tmp_list:
        tmp = e.split(':')
        dicto[tmp[0]] = tmp[1] 
    print(type(dicto))      

file=open("config.txt", "r").read()
jsondata=json.dumps(file)  
buffer(jsondata)
</code></pre>

python json python-3.x