By using json.loads() we can decode Json formatted data to Python object

In our example codes below we will check each object type after converting from Json to Python object.

Getting Boolean type
import json
print(json.loads(my_str)) # True
print(type(json.loads(my_str))) # <class 'bool'>
Getting None type
import json
print(json.loads(my_str)) # None
print(type(json.loads(my_str))) # <class 'NoneType'>
Getting a List
import json
print(json.loads(my_str)) # ['First', 'Second', 'Third']
print(type(json.loads(my_str))) # <class 'list'>
Getting a Dictionary
import json
my_str='{"id":"2","name":"Max Ruin","class1":"Three5","mark":"85"}'
print(json.loads(my_str)) # {'id': '2', 'name': 'Max Ruin', 'class1': 'Three5', 'mark': '85'}
print(type(json.loads(my_str))) # <class 'dict'>
load() to read Json data from file
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer