1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5
6print(data)
1import json
2
3appDict = {
4 'name': 'messenger',
5 'playstore': True,
6 'company': 'Facebook',
7 'price': 100
8}
9app_json = json.dumps(appDict)
10print(app_json)
1import json
2
3x = '{ "name":"John", "age":30, "city":"New York"}'
4y = json.loads(x)
5
6print(y["age"])
1import json
2
3# with json.loads (string)
4info = '{"name": "Dave","City": "NY"}'
5res = json.loads(info)
6print(res)
7print("Datatype of the serialized JSON data : " + str(type(res)))
8#>>> {'name': 'Dave', 'City': 'NY'}
9#>>> Datatype of the serialized JSON data : <class 'dict'>
10
11# with json load (file)
12info = open('data.json',)
13res = json.load(info)
14print(res)
15print("Datatype after deserialization : " + str(type(res)))
16#>>> {'name': 'Dave', 'City': 'NY'}
17#>>> Datatype of the serialized JSON data : <class 'dict'>