How to convert from a dictionary to JSON string in Python

1 Answer

0 votes
import json

dr = {"name": "Fox", "profession": "Programmer", "salary": 17500}

jsn = json.dumps(dr)

print(jsn)

l_jsn = json.loads(jsn)
print(l_jsn['name'])
print(l_jsn['profession'])
print(l_jsn['salary'])

print(type(jsn))
print(type(dr))


'''
run:

{"salary": 17500, "name": "Fox", "profession": "Programmer"}
Fox
Programmer
17500
<class 'str'>
<class 'dict'>

'''

 



answered Nov 24, 2018 by avibootz

Related questions

1 answer 331 views
1 answer 221 views
1 answer 246 views
1 answer 255 views
1 answer 259 views
1 answer 336 views
1 answer 315 views
...